IOT Virtual Lab
Home
Simulation Window
Go Back
Interfacing of Arduino with Potentiometer :
ARDUINO CODE
#define COMMON_A 12 #define SEGMENT_A 11 #define SEGMENT_B 10 #define SEGMENT_C 9 #define SEGMENT_D 8 #define SEGMENT_E 7 #define SEGMENT_F 6 #define SEGMENT_G 5 #define DECIMAL_POINT 4 // Code for CATHODE 7 SEG-DISPLAY // index and number counter int i = 0, num = 0; // Init a pinList (4- 12) int pinList[9] = { DECIMAL_POINT, SEGMENT_G , SEGMENT_F , SEGMENT_E , SEGMENT_D , SEGMENT_C , SEGMENT_B , SEGMENT_A , COMMON_A }; void setup() { for (i = 0; i <= 8; i++) { pinMode(pinList[i], OUTPUT); } } void loop() { digitalWrite(COMMON_A, LOW); if (num == 10) num = 0; switch(num) { // Displaying 0 Module case 0 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_C, HIGH); digitalWrite(SEGMENT_D, HIGH); digitalWrite(SEGMENT_E, HIGH); digitalWrite(SEGMENT_F, HIGH); break; // Displaying 1 Module case 1 : digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_C, HIGH); break; // Displaying 2 Module case 2 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_G, HIGH); digitalWrite(SEGMENT_E, HIGH); digitalWrite(SEGMENT_D, HIGH); break; // Displaying 3 Module case 3 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_G, HIGH); digitalWrite(SEGMENT_C, HIGH); digitalWrite(SEGMENT_D, HIGH); break; // Displaying 4 Module case 4 : digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_G, HIGH); digitalWrite(SEGMENT_F, HIGH); digitalWrite(SEGMENT_C, HIGH); break; // Displaying 5 Module case 5 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_F, HIGH); digitalWrite(SEGMENT_G, HIGH); digitalWrite(SEGMENT_C, HIGH); digitalWrite(SEGMENT_D, HIGH); break; // Displaying 6 Module case 6 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_F, HIGH); digitalWrite(SEGMENT_G, HIGH); digitalWrite(SEGMENT_C, HIGH); digitalWrite(SEGMENT_D, HIGH); digitalWrite(SEGMENT_E, HIGH); break; // Displaying 7 Module case 7 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_C, HIGH); break; // Displaying 8 Module case 8 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_C, HIGH); digitalWrite(SEGMENT_D, HIGH); digitalWrite(SEGMENT_E, HIGH); digitalWrite(SEGMENT_F, HIGH); digitalWrite(SEGMENT_G, HIGH); break; // Displaying 9 Module case 9 : digitalWrite(SEGMENT_A, HIGH); digitalWrite(SEGMENT_B, HIGH); digitalWrite(SEGMENT_C, HIGH); digitalWrite(SEGMENT_D, HIGH); digitalWrite(SEGMENT_F, HIGH); digitalWrite(SEGMENT_G, HIGH); break; // Displaying all segment if error occurs default: for (i = 1; i < 8; i++){ digitalWrite(pinList[i], HIGH); } // Delay for 1000 ms (1 sec) delay(1000); for (i = 1; i < 8; i++){ digitalWrite(pinList[i], LOW); } // Delay for 1000 ms (1 sec) delay(1000); for (i = 1; i < 8; i++){ digitalWrite(pinList[i], HIGH); } // Delay for 1000 ms (1 sec) delay(1000); for (i = 1; i < 8; i++){ digitalWrite(pinList[i], LOW); } // Delay for 1000 ms (1 sec) delay(1000); for (i = 1; i < 8; i++){ digitalWrite(pinList[i], HIGH); } // Delay for 1000 ms (1 sec) delay(1000); for (i = 1; i < 8; i++){ digitalWrite(pinList[i], LOW); } break; } // Increment num num++; // Delay for 1000 ms (1 sec) delay(1000); for(i = 1; i < 8; i++){ digitalWrite(pinList[i], LOW); } // Delay for 1000 ms (1 sec) delay(1000); // Display DECIMAL_POINT after every number displayed digitalWrite(DECIMAL_POINT, HIGH); // Delay for 1000 ms (1 sec) delay(1000); digitalWrite(DECIMAL_POINT, LOW); }
Start Simulation