Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int N=32;
- int i;
- int codi[32];
- unsigned long tempsinicial;
- void setup () {
- Serial.begin(9600);
- attachInterrupt(0, detecta_tecla, RISING);
- }
- void loop() {
- }
- void detecta_tecla() {
- detachInterrupt(0);
- i=0;
- tempsinicial=micros();
- attachInterrupt(0, detecta_pols, RISING);
- }
- void detecta_pols() {
- detachInterrupt(0);
- /*if (i==0){
- tempsinicial = micros();
- ++i;
- attachInterrupt(0, detecta_pols, RISING);
- }*/
- //else{
- unsigned long temps = micros();
- if (temps-tempsinicial < 1600){
- codi[i] = 0;
- }
- else {
- codi[i] = 1;
- }
- tempsinicial = temps;
- ++i;
- if (i==N){
- delay(1000);
- int j;
- for (j=0; j<N; ++j){
- Serial.print(codi[j]);
- }
- Serial.println("");
- attachInterrupt(0, detecta_tecla, RISING);
- }
- else{
- attachInterrupt(0, detecta_pols, RISING);
- }
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement