Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RCSwitch.h>
- RCSwitch mySwitch = RCSwitch();
- int teclaPress;
- boolean flagTecla[12];
- boolean flagTim[12];
- boolean flagTimC[12];
- boolean passZero;
- boolean on_off[12];
- unsigned long currentMillis;
- unsigned long TIM_T[13]={1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1100};
- unsigned long TIM_C[13];
- long int value;
- long int codTecla[12]={5635843, 5635852, 5635855, 5635888, 5635891, //CODES DE CADA TECLA
- 5635900, 5635903, 5636032, 5636035, 5636044,
- 5636047, 5636080 };
- void setup()
- {
- Serial.begin(9600);
- pinMode(13,OUTPUT);
- delay(50);
- mySwitch.enableReceive(0);
- }
- void loop()
- {
- currentMillis = millis();
- for(int i=0; i<11; i++)
- {
- if(flagTim[i]==true && currentMillis - TIM_C[i] > TIM_T[i])
- {
- //TIM_C[i]=currentMillis;
- flagTimC[i]=true;
- }
- }
- if (mySwitch.available())
- {
- value = mySwitch.getReceivedValue();
- for(int i=0; i<11; i++)
- {
- if(value==codTecla[i] && flagTim[i]==false)
- {
- TIM_C[i]=currentMillis;
- }
- if(value==codTecla[i] && flagTecla[i]==false)
- {
- flagTecla[i]=true;
- flagTim[i]=true;
- Serial.print("salta para void teclas ");
- Serial.print("tecla apertada numero :");
- Serial.println(i);
- teclaPress=i;
- teclas();
- }
- else if(value==codTecla[i] && flagTecla[i]==true && flagTimC[i]==true)
- {
- flagTecla[i]=false;
- flagTim[i]=false;
- flagTimC[i]=false;
- TIM_C[i]=currentMillis;
- }
- }
- mySwitch.resetAvailable();
- }
- }
- void teclas()
- {
- Serial.println("passo tecla press");
- switch (teclaPress)
- {
- case 0:
- if(on_off[teclaPress]==false)
- {
- on_off[teclaPress]=true;
- digitalWrite(13, LOW);
- Serial.println("passo1");
- }
- else if(on_off[teclaPress]==true)
- {
- on_off[teclaPress]=false;
- digitalWrite(13, HIGH);
- Serial.println("passo2");
- }
- break;
- case 1:
- Serial.println("tecla 2");
- break;
- case 2:
- Serial.println("tecla 3");
- break;
- case 3:
- Serial.println("tecla 4");
- break;
- case 4:
- Serial.println("tecla 5");
- break;
- case 5:
- Serial.println("tecla 6");
- break;
- case 7:
- Serial.println("tecla 8");
- break;
- case 8:
- Serial.println("tecla 9");
- break;
- case 10:
- Serial.println("tecla 11");
- break;
- case 11:
- Serial.println("tecla 12");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement