Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic and Turret control demos
- Loading branch information
Showing
40 changed files
with
595 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
RobotGeekSketches/Demos/IR/IRcontrolBasics/IRcontrolBasics.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/******************************************************************************** | ||
* RobotGeek Basic IR Control Example | ||
* | ||
* This sketch will allow you to control a servo and two LEDs in different ways | ||
* using an InfraRed Remote, configured with the IRremoteWizard Sketch, defined in | ||
* remotes.h. | ||
* | ||
* | ||
* | ||
********************************************************************************/ | ||
#include <IRLib.h> | ||
#include <Servo.h> | ||
#include "remotes.h" | ||
|
||
/* Note: Servo library uses TIMER1. The default timer for IRLib on Arduino Uno | ||
* is TIMER2 so there is no conflict. However a default timer on Arduino Leonardo | ||
* is TIMER1 so you will have to modify the timer used to use TIMER3 or TIMER4 | ||
* as specified in IRLibTimer.h. Also you will need to modify the input being used. | ||
*/ | ||
|
||
const int LED_1 = 2; // LED to be digitally controlled on pin 2 | ||
const int LED_2 = 5; // LED for PWM control on pin 9 | ||
int brightness; // how bright the LED is | ||
int fadeAmount; // how many points to fade the LED by | ||
|
||
IRrecv My_Receiver(11); // Receive Pin | ||
IRdecode My_Decoder; // decoder object | ||
Servo triggerServo; // create servo object to control a servo | ||
int triggerPos; // variable to store the trigger servo position | ||
int Speed; // Number of degrees to move each time a left/right button is pressed | ||
|
||
unsigned long lastCommand; // last command sent from IR remote | ||
|
||
void setup() | ||
{ | ||
My_Receiver.No_Output(); // Turn off any unused IR LED output circuit | ||
triggerServo.attach(6); // attaches the servo on pin 3 to the servo object | ||
triggerPos = 90; // start at midpoint 90 degrees | ||
Speed = 3; // servo moves 3 degrees each time left/right is pushed | ||
triggerServo.write(triggerPos); // Set initial position | ||
My_Receiver.enableIRIn(); // Start the receiver | ||
|
||
pinMode(LED_1, OUTPUT); | ||
pinMode(LED_2, OUTPUT); | ||
brightness = 0; // Start the LED LOW | ||
fadeAmount = 5; // set LED fade to 1 | ||
|
||
Serial.begin(9600); // start serial at 9600 baud | ||
Serial.println("startup"); // print a line when system is ready | ||
Serial.println(MY_PROTOCOL); // print the remote protocol on startup | ||
} | ||
|
||
void loop() | ||
{ | ||
if (My_Receiver.GetResults(&My_Decoder)) // read signal from decoder object | ||
{ | ||
My_Decoder.decode(); | ||
if(My_Decoder.decode_type == MY_PROTOCOL) // if decoder is using the set protocol | ||
{ | ||
Serial.println(lastCommand, HEX); // print last command to serial for debugging | ||
|
||
if(My_Decoder.value != REPEATING) // if the decoder value received is not the NEC Repeat code (0xFFFFFFFF) | ||
{ | ||
lastCommand = My_Decoder.value; // variable lastCommand gets set to the decoder value | ||
} | ||
|
||
if(lastCommand == LEFT_BUTTON) // if the last command sent is the left arrow | ||
{ | ||
triggerPos=min(180,triggerPos+Speed); // turn pan servo left | ||
} | ||
|
||
else if(lastCommand == RIGHT_BUTTON) // if the last command sent is the right arrow | ||
{ | ||
triggerPos=max(0,triggerPos-Speed); // turn pan servo right | ||
} | ||
|
||
else if(lastCommand == SELECT_BUTTON) // if the last command sent is the select/enter button | ||
{ | ||
triggerPos=90; // center pan servo | ||
} | ||
|
||
else if(lastCommand == UP_BUTTON) // if the last command sent is the up arrow | ||
{ | ||
brightness = min((brightness + fadeAmount), 255); // Brighten LED | ||
} | ||
|
||
else if(lastCommand == DOWN_BUTTON) // if the last command sent is the down arrow | ||
{ | ||
brightness = max((brightness - fadeAmount), 0); // Darken LED | ||
} | ||
|
||
else if(lastCommand == ONE_BUTTON) //if the last command sent is the 1 button | ||
{ | ||
digitalWrite(LED_1, HIGH); // turn LED on | ||
} | ||
|
||
else if(lastCommand == TWO_BUTTON) //if the last command sent is the 2 button | ||
{ | ||
digitalWrite(LED_1, LOW); // turn LED off | ||
} | ||
|
||
else if(lastCommand == SPECIAL_2_BUTTON) // if the last command sent is the volume up button | ||
{ | ||
Speed=min(10, Speed+1); // increase the speed of all servo movements | ||
} | ||
|
||
else if(lastCommand == SPECIAL_1_BUTTON) // if the last command sent is the volume down button | ||
{ | ||
Speed=max(1, Speed-1); // decrease the speed of all servo movements | ||
} | ||
triggerServo.write(triggerPos); // tell servo to go to position in variable 'triggerPos' | ||
analogWrite(LED_2, brightness); // write the brightness of the LED | ||
} | ||
My_Receiver.resume(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#define REMOTE_TYPE MINI_REMOTE_1 | ||
|
||
#define MINI_REMOTE_1 0001 | ||
#define MINI_REMOTE_2 0002 | ||
#define SONY_DVD 0003 | ||
|
||
const unsigned long REPEATING = 0xFFFFFFFF; | ||
|
||
#if REMOTE_TYPE == MINI_REMOTE_1 | ||
|
||
// You will have to set these values depending on the protocol | ||
// and remote codes that you are using. These are from the Adafruit Mini Remote | ||
const unsigned long MY_PROTOCOL = NEC; | ||
const unsigned long RIGHT_BUTTON = 0xFD50AF; | ||
const unsigned long LEFT_BUTTON = 0xFD10EF; | ||
const unsigned long UP_BUTTON = 0xFDA05F; | ||
const unsigned long DOWN_BUTTON = 0xFDB04F; | ||
const unsigned long SELECT_BUTTON = 0xFD906F; | ||
const unsigned long ONE_BUTTON = 0xFD08F7; | ||
const unsigned long TWO_BUTTON = 0xFD8877; | ||
const unsigned long THREE_BUTTON = 0xFD48B7; | ||
const unsigned long FOUR_BUTTON = 0xFD28D7; | ||
const unsigned long FIVE_BUTTON = 0xFDA857; | ||
const unsigned long SIX_BUTTON = 0xFD6897; | ||
const unsigned long SEVEN_BUTTON = 0xFD18E7; | ||
const unsigned long EIGHT_BUTTON = 0xFD9867; | ||
const unsigned long NINE_BUTTON = 0xFD58A7; | ||
const unsigned long ZERO_BUTTON = 0xFD30CF; | ||
const unsigned long SPECIAL_1_BUTTON = 0xFD00FF; | ||
const unsigned long SPECIAL_2_BUTTON = 0xFD40BF; | ||
|
||
|
||
#elif REMOTE_TYPE == MINI_REMOTE_2 | ||
|
||
// You will have to set these values depending on the protocol | ||
// and remote codes that you are using. These are from my Sony DVD/VCR | ||
const unsigned long MY_PROTOCOL = NEC; | ||
const unsigned long RIGHT_BUTTON = 0xFFC23D; | ||
const unsigned long LEFT_BUTTON = 0xFF22DD; | ||
const unsigned long UP_BUTTON = 0xFF629D; | ||
const unsigned long DOWN_BUTTON = 0xFFA857; | ||
const unsigned long SELECT_BUTTON = 0xFF02FD; | ||
const unsigned long ONE_BUTTON = 0xFF6897; | ||
const unsigned long TWO_BUTTON = 0xFF9867; | ||
const unsigned long THREE_BUTTON = 0xFFB04F; | ||
const unsigned long FOUR_BUTTON = 0xFF30CF; | ||
const unsigned long FIVE_BUTTON = 0xFF18E7; | ||
const unsigned long SIX_BUTTON = 0xFF7A85; | ||
const unsigned long SEVEN_BUTTON = 0xFF10EF; | ||
const unsigned long EIGHT_BUTTON = 0xFF38C7; | ||
const unsigned long NINE_BUTTON = 0xFF5AA5; | ||
const unsigned long ZERO_BUTTON = 0xFF4AB5; | ||
const unsigned long SPECIAL_1_BUTTON = 0xFF42BD; | ||
const unsigned long SPECIAL_2_BUTTON = 0xFF52AD; | ||
|
||
|
||
|
||
#elif REMOTE_TYPE == SONY_DVD | ||
|
||
// You will have to set these values depending on the protocol | ||
// and remote codes that you are using. These are from my Sony DVD/VCR | ||
const unsigned long MY_PROTOCOL = SONY; | ||
const unsigned long RIGHT_BUTTON = 0x3EB92; | ||
const unsigned long LEFT_BUTTON = 0xDEB92; | ||
const unsigned long UP_BUTTON = 0x9EB92; | ||
const unsigned long DOWN_BUTTON = 0x5EB92; | ||
const unsigned long SELECT_BUTTON = 0xD0B92; | ||
const unsigned long ONE_BUTTON = 0xB92; | ||
const unsigned long TWO_BUTTON = 0x80B92; | ||
const unsigned long THREE_BUTTON = 0x40B92; | ||
const unsigned long FOUR_BUTTON = 0xC0B92; | ||
const unsigned long FIVE_BUTTON = 0x20B92; | ||
const unsigned long SIX_BUTTON = 0xA0B92; | ||
const unsigned long SEVEN_BUTTON = 0x60B92; | ||
const unsigned long EIGHT_BUTTON = 0xE0B92; | ||
const unsigned long NINE_BUTTON = 0x10B92; | ||
const unsigned long ZERO_BUTTON = 0x90B92; | ||
const unsigned long SPECIAL_1_BUTTON = 0xC81; | ||
const unsigned long SPECIAL_2_BUTTON = 0x481; | ||
|
||
|
||
|
||
#endif | ||
|
||
|
123 changes: 123 additions & 0 deletions
123
RobotGeekSketches/Demos/IR/IRcontrolTurret/IRcontrolTurret.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/******************************************************************************** | ||
* RobotGeek RoboTurret IR Control Example | ||
* | ||
* This sketch will allow you to control a RoboTurret with Foam Dart Gun accessory | ||
* using an InfraRed Remote, configured with the IRremoteWizard Sketch, defined in | ||
* remotes.h. | ||
* | ||
* | ||
* | ||
********************************************************************************/ | ||
#include <IRLib.h> | ||
#include <Servo.h> | ||
#include "remotes.h" | ||
|
||
/* Note: Servo library uses TIMER1. The default timer for IRLib on Arduino Uno | ||
* is TIMER2 so there is no conflict. However a default timer on Arduino Leonardo | ||
* is TIMER1 so you will have to modify the timer used to use TIMER3 or TIMER4 | ||
* as specified in IRLibTimer.h. Also you will need to modify the input being used. | ||
*/ | ||
|
||
|
||
IRrecv My_Receiver(11); // Receive Pin | ||
IRdecode My_Decoder; // decoder object | ||
Servo triggerServo; // create servo object to control a servo | ||
Servo panServo; // create servo object to control a servo | ||
Servo tiltServo; // create servo object to control a servo | ||
int panPos; // variable to store the pan servo position | ||
int tiltPos; // variable to store the tilt servo position | ||
int triggerPos; // variable to store the trigger servo position | ||
int Speed; // Number of degrees to move each time a left/right button is pressed | ||
unsigned long lastCommand; // last command sent from IR remote | ||
|
||
void setup() | ||
{ | ||
My_Receiver.No_Output(); // Turn off any unused IR LED output circuit | ||
triggerServo.attach(3); // attaches the servo on pin 3 to the servo object | ||
panServo.attach(5); // attaches the servo on pin 5 to the servo object | ||
tiltServo.attach(6); // attaches the servo on pin 6 to the servo object | ||
triggerPos = 90; // start at midpoint 90 degrees | ||
panPos = 90; // start at midpoint 90 degrees | ||
tiltPos = 90; // start at midpoint 90 degrees | ||
Speed = 3; // servo moves 3 degrees each time left/right is pushed | ||
triggerServo.write(triggerPos); // Set initial position | ||
panServo.write(panPos); // Set initial position | ||
tiltServo.write(tiltPos); // Set initial position | ||
My_Receiver.enableIRIn(); // Start the receiver | ||
|
||
Serial.begin(9600); // start serial at 9600 baud | ||
Serial.println("startup"); // print a line when system is ready | ||
Serial.println(MY_PROTOCOL); // print the remote protocol on startup | ||
} | ||
|
||
void loop() | ||
{ | ||
if (My_Receiver.GetResults(&My_Decoder)) // read signal from decoder object | ||
{ | ||
My_Decoder.decode(); | ||
if(My_Decoder.decode_type == MY_PROTOCOL) // if decoder is using the set protocol | ||
{ | ||
Serial.println(lastCommand, HEX); // print last command to serial for debugging | ||
|
||
if(My_Decoder.value != REPEATING) // if the decoder value received is not the NEC Repeat code (0xFFFFFFFF) | ||
{ | ||
lastCommand = My_Decoder.value; // variable lastCommand gets set to the decoder value | ||
} | ||
|
||
if(lastCommand == LEFT_BUTTON) // if the last command sent is the left arrow | ||
{ | ||
panPos=min(180,panPos+Speed); // turn pan servo left | ||
} | ||
|
||
else if(lastCommand == RIGHT_BUTTON) // if the last command sent is the right arrow | ||
{ | ||
panPos=max(0,panPos-Speed); // turn pan servo right | ||
} | ||
|
||
else if(lastCommand == SELECT_BUTTON) // if the last command sent is the select/enter button | ||
{ | ||
panPos=90; // center pan servo | ||
tiltPos=90; // center tilt servo | ||
} | ||
|
||
else if(lastCommand == UP_BUTTON) // if the last command sent is the up arrow | ||
{ | ||
tiltPos=min(180,tiltPos+Speed); // tilt servo aims up, tilts back | ||
} | ||
|
||
else if(lastCommand == DOWN_BUTTON) // if the last command sent is the down arrow | ||
{ | ||
tiltPos=max(0,tiltPos-Speed); // tilt servo aims down, tilts forward | ||
} | ||
|
||
else if(lastCommand == ONE_BUTTON) //if the last command sent is the 1 button | ||
{ | ||
digitalWrite(2, HIGH); // turn LED on | ||
delay(200); // for 200ms | ||
digitalWrite(2, LOW); // turn LED off | ||
} | ||
|
||
else if(lastCommand == TWO_BUTTON) //if the last command sent is the 2 button | ||
{ | ||
triggerServo.write(113); // trigger servo to fire position | ||
delay(300); // for 300ms | ||
triggerServo.write(90); // trigger to neutral position | ||
delay(300); // wait 300ms | ||
} | ||
|
||
else if(lastCommand == SPECIAL_2_BUTTON) // if the last command sent is the volume up button | ||
{ | ||
Speed=min(10, Speed+1); // increase the speed of all servo movements | ||
} | ||
|
||
else if(lastCommand == SPECIAL_1_BUTTON) // if the last command sent is the volume down button | ||
{ | ||
Speed=max(1, Speed-1); // decrease the speed of all servo movements | ||
} | ||
triggerServo.write(triggerPos); // tell servo to go to position in variable 'triggerPos' | ||
panServo.write(panPos); // tell servo to go to position in variable 'panPos' | ||
tiltServo.write(tiltPos); // tell servo to go to position in variable 'tiltPos' | ||
} | ||
My_Receiver.resume(); | ||
} | ||
} |
Oops, something went wrong.