Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created August 9, 2016 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atduskgreg/2810a009796c7a0ea8b2aa586acc4f87 to your computer and use it in GitHub Desktop.
Save atduskgreg/2810a009796c7a0ea8b2aa586acc4f87 to your computer and use it in GitHub Desktop.
/*
* This class allows hand-sent signals to the Zibits IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
* An IR LED must be connected to Arduino PWM pin 3.
*
*
* http://arcfn.com
*/
#include <IRremote.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
/*
IR codes below are named by model, RC channel, and then F = forward, B = back, R = right, L = left, S = stop, and
combinations of those mean they occur at the same time.
In the case of the tarantula, the motion is by tank/cart, so a single motor will move the toy forward/back and
left/right at the same time. Two motors are needed to just turn or go straight.
The numbers in the IR codes are in microseconds, with (double-check this) each odd-ordered number indicating time
of the carrier frequency and each even-ordered number indicating time of no signal.
Also, the IRrecord.ino code contains a comment, "Tweak marks shorter, and spaces longer to cancel out IR receiver
distortion", which seems to indicate that rounding to the nearest 500 microseconds would give the true code.
The numbers in the codes were taken from the output of IRrecord.ino, taking the median value for each number across
3 instances of the signal.
*/
unsigned int spider1F[] = {1950, 550, 1950, 1050, 350, 1550, 400, 600, 400, 600, 350, 600, 400, 600, 400, 600, 350, 1550, 400, 1550, 400, 1550, 400, 1550, 400};
unsigned int spider1FR[] = {1900, 550, 1950, 1050, 350, 600, 400, 1550, 400, 1550, 400, 600, 350, 600, 350, 1600, 350, 600, 400, 600, 400, 1550, 400, 1550, 350};
unsigned int spider1FL[] = {1900, 550, 1950, 1050, 350, 1600, 300, 650, 400, 1550, 350, 650, 300, 700, 350, 600, 400, 1550, 350, 650, 400, 1550, 300, 1650, 300};
unsigned int spider1BR[] = {1950, 550, 1900, 1050, 400, 600, 350, 600, 400, 600, 350, 1550, 400, 600, 350, 1600, 350, 1600, 350, 1550, 400, 600, 400, 1550, 400};
unsigned int spider1BL[] = {1950, 550, 1900, 1050, 350, 1550, 300, 1600, 350, 1600, 350, 650, 300, 700, 350, 600, 400, 600, 400, 600, 350, 1600, 300, 1600, 350};
unsigned int spider1R[] = {1950, 550, 1900, 1050, 350, 650, 300, 650, 350, 1600, 350, 650, 350, 650, 300, 1600, 300, 1600, 350, 650, 350, 1600, 300, 1650, 300};
unsigned int spider1L[] = {1950, 550, 1900, 1050, 400, 1550, 350, 1550, 350, 600, 400, 600, 400, 600, 350, 600, 400, 600, 350, 1600, 350, 1550, 350, 1550, 400};
unsigned int spider1B[] = {1950, 550, 1900, 1050, 400, 600, 350, 1600, 350, 600, 400, 600, 350, 650, 350, 1550, 400, 600, 400, 1550, 350, 1600, 300, 1600, 400};
unsigned int spider1S[] = {1900, 600, 1900, 1050, 350, 600, 400, 600, 400, 600, 350, 600, 400, 600, 400, 1550, 400, 1550, 350, 1550, 350, 1550, 400, 1550, 400};
unsigned int tarantulaL2LF[] = {1900, 550, 1900, 1050, 300, 650, 350, 650, 350, 1600, 300, 650, 350, 1600, 300, 1650, 300, 1600, 350, 650, 300, 1600, 350, 650, 350};
unsigned int tarantula2RB[] = {2000, 500, 1900, 1000, 400, 600, 400, 1550, 300, 650, 350, 650, 350, 1600, 350, 1650, 300, 650, 300, 1600, 350, 1600, 350, 650, 300};
int codeLen = 25; // indicates how many elements of Codes should be sent
void loop() {
char c = Serial.read();
if (c == 'f') { // Runs for number of characters sent by serial
Serial.println("sending spider 1 forward");
irsend.sendRaw(spider1F, codeLen, 38);
delay(50);
// irsend.sendRaw(spider1S, codeLen, 38);
}
if (c == 'b') {
Serial.println("sending spider 1 back");
irsend.sendRaw(spider1B, codeLen, 38);
delay(50);
// irsend.sendRaw(spider1S, codeLen, 38);
// irsend.sendRaw(spider1S, codeLen, 38);
}
if (c == 's') {
Serial.println("sending spider 1 stop");
irsend.sendRaw(spider1S, codeLen, 38);
irsend.sendRaw(spider1S, codeLen, 38);
}
if (c == 'r') {
Serial.println("sending spider 1 right");
irsend.sendRaw(spider1R, codeLen, 38);
//delay(50);
irsend.sendRaw(spider1S, codeLen, 38);
irsend.sendRaw(spider1S, codeLen, 38);
irsend.sendRaw(spider1S, codeLen, 38);
}
if (c == 'l') {
Serial.println("sending spider 1 left");
irsend.sendRaw(spider1L, codeLen, 38);
// delay(50);
irsend.sendRaw(spider1S, codeLen, 38);
irsend.sendRaw(spider1S, codeLen, 38);
irsend.sendRaw(spider1S, codeLen, 38);
}
if (c == 'e') {
Serial.println("sending spider 1 forward right");
irsend.sendRaw(spider1FR, codeLen, 38);
delay(50);
}
if (c == 'w') {
Serial.println("sending spider 1 forward left");
irsend.sendRaw(spider1FL, codeLen, 38);
delay(50);
}
if (c == 'c') {
Serial.println("sending spider 1 back right");
irsend.sendRaw(spider1BR, codeLen, 38);
delay(50);
}
if (c == 'x') {
Serial.println("sending spider 1 back left");
irsend.sendRaw(spider1BL, codeLen, 38);
delay(50);
}
if (c == 'z') {
Serial.println("sending tarantula 2 left forward");
irsend.sendRaw(tarantulaL2LF, codeLen, 38);
delay(50);
}
if (c == 'y') {
Serial.println("sending tarantula 2 right back");
irsend.sendRaw(tarantula2RB, codeLen, 38);
}
// if (c == 'g') { // Runs for number of characters sent by serial
// Serial.println("sending quick forward");
// irsend.sendRaw(forwardCodes, codeLen, 38);
// delay(50);
// irsend.sendRaw(stopCodes, codeLen, 38);
// }
// if (c == 'r') { // Runs for number of characters sent by serial
// Serial.println("sending quick turn");
// irsend.sendRaw(rightCodes, codeLen, 38);
// delay(50);
// irsend.sendRaw(stopCodes, codeLen, 38);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment