Skip to content

Commit

Permalink
Merge pull request #4 from ernestmc/add_sleep
Browse files Browse the repository at this point in the history
Added a sleep method.
  • Loading branch information
tulku authored Sep 28, 2016
2 parents 2008c6f + e87596f commit 54b474c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
18 changes: 18 additions & 0 deletions examples/test_sleep/test_sleep.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <dreamster.h>

// Create our robot object.
Dreamster robot;

void setup() {
// Setup our robot.
robot.setup();
}

void loop() {
// Move forward for 3 seconds.
robot.move(20, 20);
robot.sleep(3000);
// Now move backwards for 3 seconds.
robot.move(-20, -20);
robot.sleep(3000);
}
4 changes: 4 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ scan KEYWORD2
read KEYWORD2
move KEYWORD2
show KEYWORD2
update KEYWORD2
setup KEYWORD2
sleep KEYWORD2

2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ author=Lucas Chiesa <lucas.chiesa@gmail.com>
maintainer=Ernesto Corbellini <ecorbe@gmail.com>
sentence=A library that makes using your Dreamster a breeze.
paragraph=This library supports all the basic functions of the Dreamster robot
category=Robotics
category=Device Control
url=http://www.dreamsterbot.org/
architectures=avr
15 changes: 14 additions & 1 deletion src/dreamster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Dreamster::scan(int &a, int &b, int &c)
c = scan_sensor(us_trigger_c_, us_echo_c_);
}

void Dreamster::read(uint16_t &left, uint16_t &right)
void Dreamster::read(int &left, int &right)
{
left = analogRead(ir_l_);
right = analogRead(ir_r_);
Expand Down Expand Up @@ -85,6 +85,19 @@ void Dreamster::setup()
Serial.begin(9600);
}

/**
* Sleep for msec milliseconds. The robot keeps updating it's status.
* @param msec Time in milliseconds to sleep.
*/
void Dreamster::sleep(long msec)
{
unsigned long start = millis();
while ((millis() - start) < msec)
{
update();
}
}

Dreamster::Motor::Motor(int pin, int dir)
{
servo.attach(pin);
Expand Down
3 changes: 2 additions & 1 deletion src/dreamster.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class Dreamster

Dreamster();
void scan(int &a, int &b, int &c);
void read(uint16_t &left, uint16_t &right);
void read(int &left, int &right);
void move(int left, int right);
void show(uint8_t red, uint8_t green, uint8_t blue);
void update();
void setup();
void sleep(long msec);

private:

Expand Down

0 comments on commit 54b474c

Please sign in to comment.