Paso 2: Programar el teensy
Proyecto: Teensy IR teclado
1 de mar - Mar 2 12
-Shawn McCombs
*/
#include
#include
int RECV_PIN = 10;
int ledPin = 11;
int todo;
int abierto;
pasos de int = 1;
int directa;
int lugar;
int modo;
pantalla int;
largo previousMillis;
largo intervalo de tiempo = 100;
Irrecv(RECV_PIN) de IRrecv;
resultados de la decode_results;
Dígitos de la cadena, doneit;
Canales de cadena [] = {}
"cero",
"http://www.youtube.com/watch?v=G17x99Sh424",
"http://www.youtube.com/watch?v=EZbrSm5psT4",
"http://www.youtube.com/watch?v=jUkoL9RE72o",
"http://www.youtube.com/watch?v=7q2bNqe0Xyk",
"http://www.youtube.com/watch?v=pMPrxg1bSPE",
"http://www.youtube.com/watch?v=J4Mb5Yt_ylk",
"http://www.youtube.com/watch?v=Zcps2fJKuAI",
"http://www.youtube.com/watch?v=-SIgu2j4Nzs",
"http://www.youtube.com/watch?v=mdJDPepGOAM",
"http://www.shoutcast.com/shoutcast_popup_player?station_id=1254140 & play_status = 1 & stn = Chillout % 20Dreams % 20-% 20DIGITALLY % 20IMPORTED % 20-% 20relax...",
"http://www.youtube.com/watch?v=bX5uSguogQM"
};
void setup()
{
irrecv.enableIRIn();
pinMode (ledPin, salida);
digitalWrite (ledPin, HIGH);
dígito = String("");
doneit = String("");
}
void loop() {}
Si (irrecv.decode (y resultados)) {}
if(Results.Value == 0x210700FF) {}
dígitos += 0;
} else if (results.value == 0x2107807F) {}
dígitos += 1;
} else if (results.value == 0x210740BF) {}
dígitos += 2;
} else if (results.value == 0x2107C03F) {}
dígitos += 3;
} else if (results.value == 0x210720DF) {}
dígitos += 4;
} else if (results.value == 0x2107A05F) {}
dígitos += 5;
} else if (results.value == 0x2107609F) {}
dígitos += 6;
} else if (results.value == 0x2107E01F) {}
dígitos += 7;
} else if (results.value == 0x210710EF) {}
dígitos += 8;
} else if (results.value == 0x2107906F) {}
+= de dígitos 9;
} else if (results.value == 0x2107EA15) {}
todo = digit.toInt();
Si (todo > 0 & & todo < 12) {}
lugar = todo;
doneit = canales [todo];
doit();
dígito = "";
todo = 0;
} else {}
error();
}
} else if (results.value == 0x210706F9) {}
volup();
directa = 5;
} else if (results.value == 0x21078679) {}
voldown();
directa = 6;
} else if (results.value == 0x210726D9) {}
MUTE();
directa = 0;
} else if (results.value == 0x21071EE1) {}
Refresh();
directa = 0;
} else if (results.value == 0x2107D926) {}
CloseWin();
abierto = 0;
directa = 0;
} else if (results.value == 0x210709F6) {}
if(Screen == 0) {}
pantalla = 1;
}
screenswitch();
directa = 0;
} else if (results.value == 0x2107CE31) {}
pasos = 1;
up();
directo = 1;
} else if (results.value == 0x21076E91) {}
if(Screen == 1) {}
Keyboard.set_key1(KEY_LEFT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
} else {}
pasos = 1;
Left();
directa = 2;
}
} else if (results.value == 0x21072ED1) {}
pasos = 1;
Down();
directa = 3;
} else if (results.value == 0x2107AE51) {}
if(Screen == 1) {}
Keyboard.set_key1(KEY_RIGHT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
} else {}
pasos = 1;
Right();
directa = 4;
}
} else if (results.value == 0x2107EE11) {}
if(Screen == 1) {}
pantalla = 0;
screenswitch();
} else {}
directa = 0;
leftmouse();
}
} else if (results.value == 0x21070EF1) {}
directa = 0;
Rightmouse();
} else if (results.value == 0x21070AF5) {}
lugar ++;
Si {} (lugar > 11)
lugar = 11;
error();
} else {}
doneit = canales [lugar];
doit();
}
} else if (results.value == 0x21078A75) {}
lugar = lugar de-1;
Si (lugar < 0) {}
lugar = 0;
error();
} else if (sitio > 0) {}
doneit = canales [lugar];
doit();
} else {}
Si (abre == 1) {}
CloseWin();
}
}
}
Si (directo > 0 & & results.value == 0xFFFFFFFF) {}
if(Direct == 1) {}
up();
} else if (directo == 2) {}
Left();
} else if (directo == 3) {}
Down();
} else if (directo == 4) {}
Right();
} else if (directo == 5) {}
volup();
} else if (directo == 6) {}
voldown();
}
unsigned currentMillis largo = millis();
Si (currentMillis - previousMillis > intervalo) {}
previousMillis = currentMillis;
pasos ++;
Si {} (pasos > 19)
pasos = 20;
}
}
}
irrecv.resume();
}
}
{} void doit()
Si (abre == 0) {}
abierto = 1;
} else {}
CloseWin();
}
Keyboard.set_modifier(MODIFIERKEY_GUI);
Keyboard.set_key1(KEY_R);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
Delay(100);
Delay(100);
Keyboard.Print(doneit);
Delay(100);
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
doneit = "";
}
error() vacío {}
digitalWrite (ledPin, LOW);
Delay(400);
digitalWrite (ledPin, HIGH);
Delay(400);
digitalWrite (ledPin, LOW);
Delay(400);
digitalWrite (ledPin, HIGH);
Delay(400);
digitalWrite (ledPin, LOW);
Delay(400);
digitalWrite (ledPin, HIGH);
Delay(400);
digitalWrite (ledPin, LOW);
Delay(400);
digitalWrite (ledPin, HIGH);
}
{} void refresh()
Keyboard.set_key1(KEY_F5);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
}
void closewin() {}
Keyboard.set_modifier(MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_F4);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void volup() {}
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_UP);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void voldown() {}
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_DOWN);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
void mute() {}
Keyboard.set_modifier(MODIFIERKEY_CTRL | MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_PERIOD);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
}
{} void up()
Mouse.Move (0,-pasos);
}
left() vacío {}
Mouse.Move (-pasos, 0);
}
{} void down()
Mouse.Move (0, pasos);
}
right() vacío {}
Mouse.Move (pasos, 0);
}
void leftmouse() {}
Mouse.click();
}
void rightmouse() {}
Mouse.set_buttons (0, 0, 1);
Mouse.set_buttons (0, 0, 0);
}
void screenswitch() {}
Si (pantalla == 1) {}
Keyboard.set_modifier(MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_TAB);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
} else {}
Keyboard.set_modifier(0);
Keyboard.send_now();
}
}