Bonjour,
Voici mon premier projet Arduino : utiliser un afficheur LCD à 7 segments:
Le making off : la caméra d’un Acer Aspire One soudée sur un câble USB, montée sur un support en LEGO, filmée par guvcview, éditée par Avidemux sous Gentoo Linux, le tout sous l’oeil bienveillant de Caroline.
Et le code associé
/*
7-Segments display example
by Xavier Miller http://www.xaviermiller.be
It displays 16 hex digits from 0 to F and dot.
Setup:
LCD display:
G F (Com) A B
| | | | |
+-----------+
| A |
| +---+ |
| F| G |B |
| + - + |
| E| |C |
| +---+ . |
| D |
+-----------+
| | | | |
E D (COM) C Dot
Arduino:
A = 2;
B = 3;
C = 4;
D = 5;
E = 6;
F = 7;
G = 8;
Dot = 9;
+ 330 ohms resistance to ground
*/
const byte pinStart = 2;
byte masks[] =
{
//GFEDCBA
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
B01110111, // A
B01111100, // b
B00111001, // C
B01011110, // d
B01111001, // E
B01110001 // F
};
void ShowDigit(byte value, byte dot)
{
// guard
if (value > sizeof(masks))
value = 0;
// get digit
byte mask = masks[value];
// apply dot
if (dot)
mask |= 128;
// display each segment
for (byte b = 0; b < 8; b++)
digitalWrite(b + pinStart, (mask & (1 << b)) ? HIGH : LOW);
}
void setup()
{
for (byte pin = 0; pin < 8; pin++)
pinMode(pin + pinStart, OUTPUT);
}
void loop()
{
for (byte dot = 0; dot < 2; dot++)
for (byte digit = 0; digit < sizeof(masks); digit++)
{
ShowDigit(digit, dot);
delay(500);
}
}



Gentoo Linux
LinkedIn profile