7 segment LED codes:
https://zxcongducxz.000webhostapp.com/arduino/SevenSegmentLEDDisplay.html
Arduino IDE Code:
const unsigned int DELAY_DISPLAY = 500;
const byte PINS[] = {4, 5, 10, 9, 8, 3, 2, 11}; // pins from left to right: A, B, C, D, E, F, G, DotPoint
const byte BYTES_DISPLAY[] = { // list of bytes to display from top to bottom, 1 byte = 8 bits, bit froms right to left
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111101, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
};
void setup() {
// put your setup code here, to run once:
for(byte indexPin = 0; indexPin < sizeof(PINS); indexPin++) {
pinMode(PINS[indexPin], OUTPUT); // set pins A, B, C, D, E, F, G are out put.
}
}
void writeDigit(byte digit) {
for(byte indexPin = 0; indexPin < sizeof(PINS); indexPin++) { // indexPin (from left to right in array) = indexBit (from right to left in calculator)
bool isOn = digit & (1 << indexPin); // get bit at indexPin; from right to left; value 0 = LED off = LOW; value 1 = LED on = HIGH
digitalWrite(PINS[indexPin], isOn); // write out put pins (A, B, C, D, E, F, G, DotPoint) on or off
}
}
void loop() {
// put your main code here, to run repeatedly:
for(byte indexNumber = 0; indexNumber < sizeof(BYTES_DISPLAY); indexNumber++) { // each display for single digit
writeDigit(BYTES_DISPLAY[indexNumber]);
delay(DELAY_DISPLAY);
}
}
How to make it:
No comments:
Post a Comment