Created
April 7, 2016 10:44
-
-
Save Steffo99/3c03c5512e381864b7e112f184fcaa9e to your computer and use it in GitHub Desktop.
This file contains 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
// P6_0 a P6_3 sono le porte del 7segmenti | |
// PUSH2 è il pulsante | |
#include <math.h> | |
void setup() | |
{ | |
pinMode(P6_0, OUTPUT); | |
pinMode(P6_1, OUTPUT); | |
pinMode(P6_2, OUTPUT); | |
pinMode(P6_3, OUTPUT); | |
pinMode(PUSH2, INPUT_PULLUP); | |
} | |
//Dobbiamo dividere in binario un numero! | |
void accendiLedGiusti(int n) | |
{ | |
int ledStatus[4]; | |
switch(n) | |
{ | |
case 0: | |
ledStatus[0] = LOW; | |
ledStatus[1] = LOW; | |
ledStatus[2] = LOW; | |
ledStatus[3] = LOW; | |
break; | |
case 1: | |
ledStatus[0] = LOW; | |
ledStatus[1] = LOW; | |
ledStatus[2] = LOW; | |
ledStatus[3] = HIGH; | |
break; | |
case 2: | |
ledStatus[0] = LOW; | |
ledStatus[1] = LOW; | |
ledStatus[2] = HIGH; | |
ledStatus[3] = LOW; | |
break; | |
case 3: | |
ledStatus[0] = LOW; | |
ledStatus[1] = LOW; | |
ledStatus[2] = HIGH; | |
ledStatus[3] = HIGH; | |
break; | |
case 4: | |
ledStatus[0] = LOW; | |
ledStatus[1] = HIGH; | |
ledStatus[2] = LOW; | |
ledStatus[3] = LOW; | |
break; | |
case 5: | |
ledStatus[0] = LOW; | |
ledStatus[1] = HIGH; | |
ledStatus[2] = LOW; | |
ledStatus[3] = HIGH; | |
break; | |
case 6: | |
ledStatus[0] = LOW; | |
ledStatus[1] = HIGH; | |
ledStatus[2] = HIGH; | |
ledStatus[3] = LOW; | |
break; | |
case 7: | |
ledStatus[0] = LOW; | |
ledStatus[1] = HIGH; | |
ledStatus[2] = HIGH; | |
ledStatus[3] = HIGH; | |
break; | |
case 8: | |
ledStatus[0] = HIGH; | |
ledStatus[1] = LOW; | |
ledStatus[2] = LOW; | |
ledStatus[3] = LOW; | |
break; | |
case 9: | |
ledStatus[0] = HIGH; | |
ledStatus[1] = LOW; | |
ledStatus[2] = LOW; | |
ledStatus[3] = HIGH; | |
break; | |
} | |
digitalWrite(P6_3, ledStatus[0]); | |
digitalWrite(P6_2, ledStatus[1]); | |
digitalWrite(P6_1, ledStatus[2]); | |
digitalWrite(P6_0, ledStatus[3]); | |
} | |
int n = 0; | |
void loop() | |
{ | |
if(digitalRead(PUSH2) == LOW) | |
{ | |
n++; | |
} | |
if(n > 9) | |
{ | |
n = 0; | |
} | |
accendiLedGiusti(n); | |
delay(200); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment