Skip to content

Commit

Permalink
Make the manual mode work properly without calling process
Browse files Browse the repository at this point in the history
  • Loading branch information
bjpirt committed Nov 20, 2014
1 parent 936a9fb commit c82079c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
25 changes: 20 additions & 5 deletions Mirobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ Mirobot::Mirobot(){
lastLedChange = millis();
}

void Mirobot::setup(){
HotStepper::setup(TIMER1INT);
// Set up the pen arm servo
pinMode(SERVO_PIN, OUTPUT);
// Set up the collision sensor inputs and state
pinMode(LEFT_COLLIDE_SENSOR, INPUT_PULLUP);
pinMode(RIGHT_COLLIDE_SENSOR, INPUT_PULLUP);
collideState = NORMAL;
//setPenState(UP);
// Set up the status LED
pinMode(STATUS_LED, OUTPUT);
}

void Mirobot::setup(Stream &s){
HotStepper::setup(TIMER1INT);
// Set up the pen arm servo
Expand Down Expand Up @@ -105,10 +118,12 @@ void Mirobot::right(int angle){

void Mirobot::penup(){
setPenState(UP);
wait();
}

void Mirobot::pendown(){
setPenState(DOWN);
wait();
}

void Mirobot::pause(){
Expand Down Expand Up @@ -152,13 +167,13 @@ boolean Mirobot::ready(){
return (motor1.ready() && motor2.ready() && !servo_pulses_left);
}

void Mirobot::setBlocking(boolean val){
blocking = val;
}

void Mirobot::wait(){
if(blocking){
while(!ready()){}
while(!ready()){
if(servo_pulses_left){
servoHandler();
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Mirobot.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct HwVersion {
class Mirobot {
public:
Mirobot();
void setup();
void setup(Stream &s);
void forward(int distance);
void back(int distance);
Expand All @@ -63,9 +64,9 @@ class Mirobot {
void beep(int);
void setHwVersion(char&);
boolean ready();
void setBlocking(boolean val);
void process();
HwVersion hwVersion;
boolean blocking;
private:
void wait();
void followHandler();
Expand All @@ -78,7 +79,6 @@ class Mirobot {
mainState_t mainState;
collideState_t collideState;
unsigned long lastLedChange;
boolean blocking;
Mirobot& self() { return *this; }
penState_t penState;
void setPenState(penState_t);
Expand Down
9 changes: 3 additions & 6 deletions examples/manual_example/manual_example.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#define HOTSTEPPER_TIMER1
#include <stdlib.h>
#include <HotStepper.h>
#include <Mirobot.h>
#include <EEPROM.h>

Mirobot mirobot;

/*
This sketch shows how you can program Mirobot directly in the Arduino environment.
*/

Mirobot mirobot;

void setup(){
mirobot.setup();
}
Expand All @@ -33,4 +30,4 @@ void loop(){
mirobot.penup();

delay(10000);
}
}

0 comments on commit c82079c

Please sign in to comment.