Write a complete Arduino program to control the following system. The settings o
ID: 3552156 • Letter: W
Question
Write a complete Arduino program to control the following system.
The settings of the four switches cause a digit to be displayed on the 7-segment LED
(common cathode) according to the table above. The four settings on the switch also
cause the servo to be positioned proportionally to the value in the table.
As illustrated in the figure above, the seven segments of the display are to be
connected to the Arduino pins 0-6. The four switches may be connected to any other
Arduino pins. The servo's one wire may also be connected to any other Arduino pin.
Explanation / Answer
long n = 0; int x = 100; int del = 1; void setup(){ // clearLEDs(); // testLEDs(); pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT); pinMode(5, OUTPUT); pinMode(4, OUTPUT); pinMode(3, OUTPUT); pinMode(2, OUTPUT); pinMode(1, OUTPUT); } void loop(){ clearLEDs(); pickDigit(1); pickNumber((n/x/1000)%10); delayMicroseconds(del); clearLEDs(); pickDigit(2); pickNumber((n/x/100)%10); delayMicroseconds(del); clearLEDs(); pickDigit(3); pickNumber((n/x/10)%10); delayMicroseconds(del); clearLEDs(); pickDigit(4); pickNumber(n/x % 10); delayMicroseconds(del); if(n/x > 9999){ n = 0; delay(115000); } else n++; } void pickDigit(int x){ digitalWrite(13, LOW); // dig 1 digitalWrite(12, LOW); // dig 2 digitalWrite( 9, LOW); // dig 3 digitalWrite( 8, LOW); // dig 4 switch(x){ case 1: digitalWrite(13, HIGH); break; case 2: digitalWrite(12, HIGH); break; case 3: digitalWrite(9, HIGH); break; case 4: digitalWrite(8, HIGH); break; } } void pickNumber(int x){ switch(x){ case 8: eight(); break; } } void clearLEDs(){ //digitalWrite(13, HIGH); // digitalWrite(12, HIGH); //digitalWrite(9, HIGH); // digitalWrite(8, HIGH); digitalWrite( 5, HIGH); // A digitalWrite( 7, HIGH); // B digitalWrite( 4, HIGH); // C digitalWrite(11, HIGH); // D digitalWrite(10, HIGH); // E digitalWrite( 3, HIGH); // F digitalWrite( 6, HIGH); // G } void eight(){ digitalWrite( 5, LOW); // A digitalWrite( 7, LOW); // B digitalWrite( 4, LOW); // C digitalWrite(11, LOW); // D digitalWrite(10, LOW); // E digitalWrite( 3, LOW); // F digitalWrite( 6, LOW); // G }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.