Teensy IR-PC Remote tangentbord & mus / Youtube spellista spelare (2 / 2 steg)
Steg 2: Programmera din teensy
Projekt: Teensy IR-tangentbord
1 mar - Mar 2 12
-Shawn McCombs
*/
#include
#include
int RECV_PIN = 10;
int ledPin = 11;
int todo;
int öppnas;
int steg = 1;
int direkt.
int plats;
int läge;
int skärmen;
lång previousMillis;
långa intervall = 100;
IRrecv irrecv(RECV_PIN);
decode_results resultat.
Sträng siffra, doneit;
Sträng kanaler [] = {
"noll",
"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, produktionen);
digitalWrite (ledPin, hög);
siffra = String("");
doneit = String("");
}
void loop() {
om (irrecv.decode (& resultat)) {
IF(results.Value == 0x210700FF) {
siffriga += 0;
} else om (results.value == 0x2107807F) {
siffriga + = 1;
} else om (results.value == 0x210740BF) {
siffriga + = 2;
} else om (results.value == 0x2107C03F) {
siffriga += 3.
} else om (results.value == 0x210720DF) {
siffriga += 4.
} else om (results.value == 0x2107A05F) {
siffriga += 5.
} else om (results.value == 0x2107609F) {
siffriga += 6.
} else om (results.value == 0x2107E01F) {
siffriga += 7.
} else om (results.value == 0x210710EF) {
siffriga += 8.
} else om (results.value == 0x2107906F) {
siffriga += 9.
} else om (results.value == 0x2107EA15) {
todo = digit.toInt();
om (todo > 0 & & todo < 12) {
Placera = todo;
doneit = kanaler [todo];
doit();
siffra = "";
todo = 0;
} annat {
error();
}
} else om (results.value == 0x210706F9) {
volup();
Direct = 5.
} else om (results.value == 0x21078679) {
voldown();
Direct = 6.
} else om (results.value == 0x210726D9) {
Mute();
Direct = 0;
} else om (results.value == 0x21071EE1) {
Refresh();
Direct = 0;
} else om (results.value == 0x2107D926) {
closewin();
öppnade = 0;
Direct = 0;
} else om (results.value == 0x210709F6) {
IF(Screen == 0) {
skärmen = 1;
}
screenswitch();
Direct = 0;
} else om (results.value == 0x2107CE31) {
steg = 1;
up();
Direct = 1;
} else om (results.value == 0x21076E91) {
IF(Screen == 1) {
Keyboard.set_key1(KEY_LEFT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
} annat {
steg = 1;
Left();
Direct = 2;
}
} else om (results.value == 0x21072ED1) {
steg = 1;
Down();
Direct = 3.
} else om (results.value == 0x2107AE51) {
IF(Screen == 1) {
Keyboard.set_key1(KEY_RIGHT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
} annat {
steg = 1;
Right();
Direct = 4.
}
} else om (results.value == 0x2107EE11) {
IF(Screen == 1) {
skärmen = 0;
screenswitch();
} annat {
Direct = 0;
leftmouse();
}
} else om (results.value == 0x21070EF1) {
Direct = 0;
rightmouse();
} else om (results.value == 0x21070AF5) {
plats ++;
om (plats > 11) {
Placera = 11;
error();
} annat {
doneit = kanaler [plats];
doit();
}
} else om (results.value == 0x21078A75) {
Placera = plats - 1.
om (plats < 0) {
Placera = 0;
error();
} else om (plats > 0) {
doneit = kanaler [plats];
doit();
} annat {
om (öppnade == 1) {
closewin();
}
}
}
om (direkt > 0 & & results.value == 0xFFFFFFFF) {
IF(Direct == 1) {
up();
} else om (direkt == 2) {
Left();
} else om (direkt == 3) {
Down();
} else om (direkt == 4) {
Right();
} else om (direkt == 5) {
volup();
} else om (direkt == 6) {
voldown();
}
osignerade långa currentMillis = millis();
om (currentMillis - previousMillis > intervall) {
previousMillis = currentMillis;
steg ++;
om (steg > 19) {
steg = 20;
}
}
}
irrecv.Resume();
}
}
void doit() {
om (öppnade == 0) {
öppnade = 1;
} annat {
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 = "";
}
void error() {
digitalWrite (ledPin, låg);
Delay(400);
digitalWrite (ledPin, hög);
Delay(400);
digitalWrite (ledPin, låg);
Delay(400);
digitalWrite (ledPin, hög);
Delay(400);
digitalWrite (ledPin, låg);
Delay(400);
digitalWrite (ledPin, hög);
Delay(400);
digitalWrite (ledPin, låg);
Delay(400);
digitalWrite (ledPin, hög);
}
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,-steg);
}
void left() {
Mouse.Move (-steg, 0);
}
void down() {
Mouse.Move (0, steg);
}
void right() {
Mouse.Move (steg, 0);
}
void leftmouse() {
Mouse.Click();
}
void rightmouse() {
Mouse.set_buttons (0, 0, 1);
Mouse.set_buttons (0, 0, 0);
}
void screenswitch() {
om (skärmen == 1) {
Keyboard.set_modifier(MODIFIERKEY_ALT);
Keyboard.set_key1(KEY_TAB);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
} annat {
Keyboard.set_modifier(0);
Keyboard.send_now();
}
}