Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* g f kc a b (pin 0) -> a
- | | | | | (pin 1) -> b
- ------------- (pin 2) -> c
- | a | (pin 3) -> d
- | --- | (pin 4) -> e
- | f | g | b | (pin 5) -> f
- | --- | (pin 6) -> g
- | e | | c | kc -> GND
- | --- | dp -> NC
- | d |
- -------------
- | | | | |
- e d kc c dp */
- #define pulsante 10
- #define a 0
- #define b 1
- #define c 2
- #define d 3
- #define e 4
- #define f 5
- #define g 6
- #define dp 7
- // Lookup table per display catodo comune: B0gfedcba
- byte lookup_7segmenti_catodocomune[10] = {
- B00111111, B00000110, B01011011, B01001111, B01100110,
- B01101101, B01111101, B00000111, B01111111, B01101111 };
- int statopresentepulsante = LOW;
- int statoprecedentepulsante = LOW;
- int numero;
- void setup(){
- pinMode(pulsante, INPUT);
- pinMode(a, OUTPUT);
- pinMode(b, OUTPUT);
- pinMode(c, OUTPUT);
- pinMode(d, OUTPUT);
- pinMode(e, OUTPUT);
- pinMode(f, OUTPUT);
- pinMode(g, OUTPUT);
- randomSeed(analogRead(0));
- }
- void displayWrite(int numero)
- {
- for (int i=a; i<=g; i++)
- {
- digitalWrite(i,numero&1);
- numero = numero >> 1;
- }
- }
- void loop() {
- statopresentepulsante = digitalRead (A0);
- if ((statopresentepulsante == HIGH)&&(statoprecedentepulsante == LOW))
- {
- numero=random(1,7);
- }
- statoprecedentepulsante = statopresentepulsante;
- delay (50);
- displayWrite(lookup_7segmenti_catodocomune[numero]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement