Last active
August 29, 2015 14:06
-
-
Save vectorcrumb/96f53be4f1ac2e1df897 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /*************************************************************/ | |
| /* Conecciones: */ | |
| /* GND--->GND */ | |
| /* +5V--->5V */ | |
| /* Rx --->A0 */ | |
| /* Ry --->A1 */ | |
| /* SW --->D12 */ | |
| /*************************************************************/ | |
| //Variables para contener los valores analogicos | |
| int x, y; | |
| //Pin al cual se encuentra conectado el interruptor | |
| byte sw = 12; | |
| //Estado actual del boton | |
| boolean sw_stat = false; | |
| //Funcion para prender y apagar la led integrada al arduino | |
| void blink(int time){ | |
| digitalWrite(13, HIGH); | |
| delay(time); | |
| digitalWrite(13, LOW); | |
| delay(time); | |
| } | |
| //Inicializacion. Se activa la comunicacion serial con el PC a 9.6 kBps, se declara el interruptor como entrada, | |
| //la led como salida y se pestañea la led | |
| void setup(){ | |
| Serial.begin(9600); | |
| pinMode(sw, INPUT); | |
| pinMode(13, OUTPUT); | |
| blink(500); | |
| } | |
| //Ciclo Principal | |
| void loop(){ | |
| //Lectura de ambos ejes analogicos | |
| x = analogRead(A0); | |
| y = analogRead(A1); | |
| //Lectura del estado del boton | |
| sw_stat = digitalRead(sw); | |
| //Se envian los resultados al PC | |
| Serial.println("Estado del eje X: " + x); | |
| Serial.println("Estado del eje Y: " + y); | |
| Serial.println("Estado del boton: " + sw_stat); | |
| //Si el boton esta activado, se prende la led, de lo contrario, se apaga | |
| if(sw_stat){ | |
| digitalWrite(13, HIGH); | |
| } else { | |
| digitalWrite(13, LOW); | |
| } | |
| Pequeño descanso para no saturar la CPU | |
| delay(5); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment