Created
May 24, 2012 16:06
-
-
Save everblut/2782443 to your computer and use it in GitHub Desktop.
Control Musica
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
/*Variables a usar*/ | |
int latch = 2; // set the latch pin | |
int clock = 3; // set the clock pin | |
int datin = 4;// set the data in pin | |
byte datosDelControl = 0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(latch,OUTPUT); | |
pinMode(clock,OUTPUT); | |
pinMode(datin,INPUT); | |
digitalWrite(latch,HIGH); | |
digitalWrite(clock,HIGH); | |
} | |
/* lectura del control */ | |
void lecturaNespad() { | |
datosDelControl = 0; | |
digitalWrite(latch,LOW); | |
digitalWrite(clock,LOW); | |
digitalWrite(latch,HIGH); | |
delayMicroseconds(2); | |
digitalWrite(latch,LOW); | |
datosDelControl = digitalRead(datin); | |
for (int i = 1; i <= 7; i ++) { | |
digitalWrite(clock,HIGH); | |
delayMicroseconds(2); | |
datosDelControl = datosDelControl << 1; | |
datosDelControl = datosDelControl + digitalRead(datin) ; | |
delayMicroseconds(4); | |
digitalWrite(clock,LOW); | |
} | |
} | |
/* ciclo */ | |
void loop() { | |
lecturaNespad(); | |
if (controller_data==B11110111){ | |
Serial.print("U"); //UP | |
} | |
if (controller_data==B11111011){ | |
Serial.print("D");//DOWN | |
} | |
if (controller_data==B11111101){ | |
Serial.print("L");//LEFT | |
} | |
if (controller_data==B11111110){ | |
Serial.print("R");//RIGHT | |
} | |
if (controller_data==B01111111){ | |
Serial.print("A");//A | |
} | |
if (controller_data==B10111111){ | |
Serial.print("B");//B | |
} | |
if (controller_data==B11101111){ | |
Serial.print("S");//START | |
} | |
if (controller_data==B11011111){ | |
Serial.print("C");//SELECT | |
} | |
if (controller_data==B11111111){ | |
Serial.print("N");//Nada... | |
} | |
delay(150); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment