Mercurial > tote
changeset 178:fcd4dbd0462f follow
Follower code
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Fri, 24 Jul 2015 14:22:16 +0200 |
| parents | 9aa456eb0395 |
| children | e4f0f2000ef4 |
| files | start/beep.ino start/clock.h start/creep.ino start/ir.ino start/sharp.ino |
| diffstat | 5 files changed, 28 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/start/beep.ino Fri Jul 10 21:14:19 2015 +0200 +++ b/start/beep.ino Fri Jul 24 14:22:16 2015 +0200 @@ -1,6 +1,6 @@ -#define BEEP_PIN 3 +#define BEEP_PIN 13 -bool beep_mute = true; +bool beep_mute = false; void beep_setup() {
--- a/start/clock.h Fri Jul 10 21:14:19 2015 +0200 +++ b/start/clock.h Fri Jul 24 14:22:16 2015 +0200 @@ -1,7 +1,7 @@ #ifndef CLOCK_H #define CLOCK_H -#define FPS 10 +#define FPS 25 const unsigned char TICK = 1000 / FPS; void tick(unsigned int ms);
--- a/start/creep.ino Fri Jul 10 21:14:19 2015 +0200 +++ b/start/creep.ino Fri Jul 24 14:22:16 2015 +0200 @@ -2,11 +2,8 @@ #include "misc.h" #include "leg.h" #include "clock.h" -#include "beep.h" -const unsigned int tones[4] = {880, 988, 1318, 1175}; - /* Creep gait parameters. */ #ifdef TOTE2 #define SPEED 1 @@ -106,12 +103,10 @@ void _creep_step(unsigned char leg) { _shift_body(leg); _on_ground[leg] = false; - beep(440, 5); for (unsigned char step = 0; step < RAISE_STEPS; ++step) { move_leg_by(leg, 0, 0, RAISE); _creep_tick(); } - beep(tones[leg], 25); move_leg( leg, HOME + (_shift_x + creep_dx * STRIDE) * LEG_X[leg] + creep_spread, @@ -120,7 +115,6 @@ ); _creep_tick(); _creep_tick(); - beep(1865, 5); for (unsigned char step = 0; step < RAISE_STEPS - 1; ++step) { move_leg_by(leg, 0, 0, -RAISE); _creep_tick();
--- a/start/ir.ino Fri Jul 10 21:14:19 2015 +0200 +++ b/start/ir.ino Fri Jul 24 14:22:16 2015 +0200 @@ -6,7 +6,6 @@ #include "IRLremote.h" -#define LED_PIN 13 #define IR_INTERRUPT 0 // Sensor on PIN 2 #define IR_PROTOCOL IR_NEC #define IR_ADDRESS 0xFF00 @@ -36,21 +35,13 @@ void ir_setup() { IRLbegin<IR_ALL>(IR_INTERRUPT); - pinMode(LED_PIN, OUTPUT); - digitalWrite(LED_PIN, LOW); - Serial.begin(115200); } void ir_loop() { static uint32_t last=0; uint32_t IRcommand = 0; - bool led = true; if (!IRLavailable()) { - if (led) { - digitalWrite(LED_PIN, LOW); - led = false; - } return; } @@ -65,7 +56,6 @@ last = IRcommand; beep(1319, 50); - digitalWrite(LED_PIN, HIGH); switch (IRcommand) { case KEY_UP: // Up arrow. @@ -109,7 +99,6 @@ break; case KEY_POWER: // Power. case KEY_POWER2: // Power. - digitalWrite(LED_PIN, LOW); robot_mode = 0; break; case KEY_SEARCH: // Search.
--- a/start/sharp.ino Fri Jul 10 21:14:19 2015 +0200 +++ b/start/sharp.ino Fri Jul 24 14:22:16 2015 +0200 @@ -1,15 +1,38 @@ #include "creep.h" - +#include "beep.h" void sharp_setup() { pinMode(A4, INPUT); + Serial.begin(115200); } void sharp_loop() { + int distance = 0; + for (unsigned char i=0; i<10; ++i) { + distance += analogRead(A4); + } + distance /= 10; + Serial.println(distance); // Stop if there is an object closer than 15cm ahead. - if (analogRead(A4) > 465) { + if (distance > 660) { + creep_dx = 0; + creep_dy = -1; + creep_rotation = 0; + beep(352, 100); + } else if (distance > 480) { creep_dx = 0; creep_dy = 0; + creep_rotation = 0; + } else if (distance > 420) { + creep_dx = 0; + creep_dy = 1; + creep_rotation = 0; + beep(704, 100); + } else { + creep_dx = 0; + creep_dy = 0; + creep_rotation = PI/45; + beep(1408, 100); } }
