/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Counter Display" - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-06-10 03:13:01 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Make a counter */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include // https://github.com/alikabeel/Letters-and-Numbers-Seven-Segment-Display-Library #include // https://github.com/evert-arias/EasyButton /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); void onPressed(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t myPushButton_PushButton_PIN_D10 = 10; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2 = 2; const uint8_t Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3 = 3; const uint8_t Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4 = 4; const uint8_t Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5 = 5; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2_rawData = 0; bool Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3_rawData = 0; bool Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4_rawData = 0; bool Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2_phyData = 0.0; float Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3_phyData = 0.0; float Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4_phyData = 0.0; float Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(myPushButton_PushButton_PIN_D10); SevenSegmentDisplay display(Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2, Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3, Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4, Display_SevenSegmentDisplayWithCommonCathode_D5, 6, 7, 8, 9, false); // Assuming common cathode display /****** COUNTER VARIABLE *****/ int counter = 0; void onPressed() { Serial.println("Button pressed"); counter++; // Increment the counter if (counter > 9) counter = 0; // Reset counter if it exceeds 9 display.displayCharacter('0' + counter); // Display the counter value } void setup(void) { // put your setup code here, to run once: Serial.begin(115200); Serial.println(); Serial.println(">>> Seven Segment Display and Button Example <<<"); pinMode(myPushButton_PushButton_PIN_D10, INPUT_PULLUP); pinMode(Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2, OUTPUT); pinMode(Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3, OUTPUT); pinMode(Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4, OUTPUT); pinMode(Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5, OUTPUT); button.begin(); button.onPressed(onPressed); } void loop(void) { // put your main code here, to run repeatedly: button.read(); updateOutputs(); // Refresh output data } void updateOutputs() { digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2, Display_SevenSegmentDisplayWithCommonCathode_A_PIN_D2_rawData); digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3, Display_SevenSegmentDisplayWithCommonCathode_B_PIN_D3_rawData); digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4, Display_SevenSegmentDisplayWithCommonCathode_C_PIN_D4_rawData); digitalWrite(Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5, Display_SevenSegmentDisplayWithCommonCathode_D_PIN_D5_rawData); } /* END CODE */