ActivityBot with SONY Remote
Andy Lindsay (Parallax)
Posts: 1,919
The Navigate With Infrared Flashlights tutorial for the ActivityBot was added to the rest of the ActivityBot tutorials on Friday:
http://learn.parallax.com/activitybot
http://learn.parallax.com/activitybot/navigate-infrared-flashlights
Here's a sneak peek at a related project that's coming soon to learn:
Circuit
http://learn.parallax.com/activitybot/build-ir-sensor-circuits
...although you can just use the IR receiver connected to P10.
Libraries
Copy the SONY Remote folder inside the attached zip to ...Documents/SimpleIDE/Learn/Simple Libraries/
Make sure you're running the latest version of SimpleIDE (0.9.43).
Restart SimpleIDE if it's running.
Test Code
Use the New Project button to create, name and save a new project.
Paste this code, then click Run with Terminal.
Point your remote at your ActivityBot and try pressing its various buttons. Verify that the digit keys match what's displayed as you press and hold them.
Navigation Code
Repeat the test code steps, but this time, use the Load EEPROM & Run button.
Unplug from the programming cable, and press and hold buttons to control. 2 or Channel up are forward, 8 or channel down are backward. 4 or volume down are turn left, 6 or volume up are turn right, and 1, 3, 7, and 9 are pivot keys.
http://learn.parallax.com/activitybot
http://learn.parallax.com/activitybot/navigate-infrared-flashlights
Here's a sneak peek at a related project that's coming soon to learn:
Circuit
http://learn.parallax.com/activitybot/build-ir-sensor-circuits
...although you can just use the IR receiver connected to P10.
Libraries
Copy the SONY Remote folder inside the attached zip to ...Documents/SimpleIDE/Learn/Simple Libraries/
Make sure you're running the latest version of SimpleIDE (0.9.43).
Restart SimpleIDE if it's running.
Test Code
Use the New Project button to create, name and save a new project.
Paste this code, then click Run with Terminal.
Point your remote at your ActivityBot and try pressing its various buttons. Verify that the digit keys match what's displayed as you press and hold them.
/* Test SONY Remote Keys.c */ #include "simpletools.h" // Library includes #include "sonyremote.h" int main() // Main function { ir_tLimit(1000); // -1 if no remote in 1 s while(1) // Repeat indefinitely { print("%c ir key = %d%c", // Display key pressed HOME, ir_key(10), CLREOL); pause(100); // 1/10 s before loop repeat } }
Navigation Code
Repeat the test code steps, but this time, use the Load EEPROM & Run button.
Unplug from the programming cable, and press and hold buttons to control. 2 or Channel up are forward, 8 or channel down are backward. 4 or volume down are turn left, 6 or volume up are turn right, and 1, 3, 7, and 9 are pivot keys.
/* ActivityBot SONY Remote Control.c */ #include "simpletools.h" // Library includes #include "sonyremote.h" #include "abdrive.h" int key; // Remote key variable int main() // Main funciton { freqout(4, 2000, 3000); // Start beep drive_setRampStep(12); // 12 ticks/sec per 20 ms ir_tLimit(50); // Remote timeout = 50 ms while(1) // Main loop { key = ir_key(12); // Get remote key code if(key == 2 || key == CH_UP) // 2 or CH_UP -> Forward drive_rampStep(128, 128); if(key == 8 || key == CH_DN) // 8 or CH_DN -> Backward drive_rampStep(-128, -128); if(key == 4 || key == VOL_DN) // 4 or VOL_DN -> Left turn drive_rampStep(-128, 128); if(key == 6 || key == VOL_UP) // 6 or VOL_UP -> Right turn drive_rampStep(128, -128); if(key == 1) // 1 -> Left forward pivot drive_rampStep(128, 0); if(key == 7) // 7 -> Left backward pivot drive_rampStep(-128, 0); if(key == 3) // 3 -> Right forward pivot drive_rampStep(0, 128); if(key == 9) // 9 -> Right backward pivot drive_rampStep(0, -128); if(key == -1 || key == MUTE) // no key or MUTE -> stay still drive_rampStep(0, 0); } }
Comments
I ONLY HAD TO CHANGE
key = ir_key(12); // Get remote key code
TO
key = ir_key(10); // Get remote key code
DUE I HAVE CONNECTED THE IR_DETECTOR IN PIN 10
MY BEST REGARDS AND HAVE A GOOD DAY
ENG. JESUS PEREZ CARREÑO (From Mexico)