I need the Arduino code for this question please? Problem 2: A single, common-an
ID: 2080382 • Letter: I
Question
I need the Arduino code for this question please?
Problem 2: A single, common-anode, 7 segment LED is connected to the Arduino Connector J1 through current-limiting resistors. The diagram in Figure 2 shows the mapping of the pins of the connector to the pins of the 7-segment. Thus, by outputting a byte to the pins of connector Ji, we can display a character. Write an Arduino program that displays the sequence of characters S-O-S (blank), each character displayed for l second. This sequence should repeat. Use the DDR. Data, and Bit registers. A B C D El F G Figure 2: Seven Segment Display HINT: Note that all the bits of J1 are counected to ATMega port D. By setting these bits as output bits, and setting the bits to 10010100, the character 3 is displayed (the LEDs are asserted low). (latch the pins of the J1 connector to their corresponding LED segment.) To Do Notifications Messages Courses Calendar
Explanation / Answer
// Define the LED digit patters, from 0 - 9
// Note that these patterns are for common cathode displays
// For common anode displays, change the 1's to 0's and 0's to 1's
// 1 = LED on, 0 = LED off, in this order:
// Arduino pin: 2,3,4,5,6,7,8
byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
{ 0,1,1,0,0,0,0 }, // = 1
{ 1,1,0,1,1,0,1 }, // = 2
{ 1,1,1,1,0,0,1 }, // = 3
{ 0,1,1,0,0,1,1 }, // = 4
{ 1,0,1,1,0,1,1 }, // = 5
{ 1,0,1,1,1,1,1 }, // = 6
{ 1,1,1,0,0,0,0 }, // = 7
{ 1,1,1,1,1,1,1 }, // = 8
{ 1,1,1,0,0,1,1 } // = 9
};
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
writeDot(0); // start with the "dot" off
}
void writeDot(byte dot) {
digitalWrite(9, dot);
}
void sevenSegWrite(byte digit) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void loop() {
for (byte count = 10; count > 0; --count) {
delay(1000);
sevenSegWrite(count - 1);
}
delay(4000);
}