Platforma de dezvoltare folosita este Arduino Uno.
Codul permite sa aprinzi un afisaj LED 7 segmente prin introducere de la tastatura din SERIAL MONITOR a nr 0 la 9 si eventual litere.
Mai multe informatii despre codul ASCII aici: http://www.ascii-code.com/ Cod:
//aprindere afisaj LED 7 segmente prin introducere de la tastatura din SERIAL MONITOR a nr 0 la 9 *Adi Ivan*
int incomingByte = 0; //pentru intrare serial data
void setup() {
Serial.begin(9600); // deschidere port serial si setare rata de transfer a datelor la 9600 bps
//seteaza iesirile
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
//stinge afisajul
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
digitalWrite(9, 1);
}
void loop()
{
// trimite date doar cand primeste date de la tastatura:
if (Serial.available() > 0) {
// citeste numarul introdus de la tastatura:
incomingByte = Serial.read();
// afiseaza in Serial Monitor numarul introdus:
Serial.print("S-a tastat: ");
Serial.println(incomingByte - 48, DEC); //S-a scazut 48 pentru a afisa in Serial Monitor exact numarul tastat (a se vedea codul ASCII)
}
if(incomingByte==48) //afisare 0. (0=48 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 1);
}
if(incomingByte==49) // afisare 1. (1=49 in cod ASCII)
{
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
}
if(incomingByte==50) // afisare 2. (2=50 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 1);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 1);
digitalWrite(8, 0);
}
if(incomingByte==51) // afisare 3. (3=51 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 0);
}
if(incomingByte==52) // afisare 4. (4=52 in cod ASCII)
{
digitalWrite(2, 1);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 0);
digitalWrite(8, 0);
}
if(incomingByte==53) // afisare 5. (5=53 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 1);
digitalWrite(7, 0);
digitalWrite(8, 0);
}
if(incomingByte==54) // afisare 6. (6=54 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 1);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
}
if(incomingByte==55) // afisare 7. (7=55 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
}
if(incomingByte==56) // afisare 8. (8=56 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
}
if(incomingByte==57) // afisare 9. (9=57 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 1);
digitalWrite(7, 0);
digitalWrite(8, 0);
}
if(incomingByte==46) //aprinde punctul. (.=46 in cod ASCII)
{
digitalWrite(9, 0);
}
if(incomingByte==65) // afisare A. (A=65 in cod ASCII)
{
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 1);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
}
if(incomingByte==32) //stinge afisajul. (tasta Space=32 in cod ASCII)
{
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
digitalWrite(9, 1);
}
}