Skip to content

Instantly share code, notes, and snippets.

@AlessandroSpallina
Created February 24, 2015 09:51
Show Gist options
  • Save AlessandroSpallina/4fed3ea074fdf0d4f44d to your computer and use it in GitHub Desktop.
Save AlessandroSpallina/4fed3ea074fdf0d4f44d to your computer and use it in GitHub Desktop.
legge stringa e lampeggia led di conseguenza
/*
Alessandro Spallina
[email protected]
http://aleksnote.altervista.org
Lorenzo Siena
[email protected]
* * * * * * * * * * * * * * * * * * * * * * * * * * * *
Legge una stringa e accende il led 3 se 'a', il led 13 se 'b', resta spento
in caso contrario. Quando arriva a fine stringa i led 3 e 13 rimangono accesi.
*/
#include <stdio.h>
int led=3;
int controllo=13;
int posizione=0;
char stringa[]="abababzzzzzzhdhdhuabbbba";
//*******************************************
int leggi()
{
switch(stringa[posizione])
{
case 'a':
posizione++;
return 1;
case 'b':
posizione++;
return 2;
case '\0':
return 999;
default:
posizione++;
return -1;
}
}
//-----------------------------------------
void lampeggia(int who)
{
switch(who)
{
case 3:
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
break;
case 13:
digitalWrite(controllo, HIGH);
delay(500);
digitalWrite(controllo, LOW);
delay(500);
break;
case 999:
digitalWrite(led, HIGH);
digitalWrite(controllo, HIGH);
break;
}
}
//*******************************************
void setup()
{
pinMode(led, OUTPUT);
pinMode(controllo, OUTPUT);
}
void loop()
{
switch(leggi())
{
case 1: //legge 'a'
lampeggia(led);
break;
case 2: //legge 'b'
lampeggia(controllo);
break;
case 999:
lampeggia(999);
break;
default:
delay(1000);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment