CCCPaste

"Button Memory" rev_04

/********* 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: "Button Memory"
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-12-29 10:04:47

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* If pushbutton P1 is pressed, read the values of */
	/* AI1 and AI2 and save to EEPROM when pushbutton P1 */
	/* is OFF then stop reading values of AI1 and AI2 and */
	/* print on serial all saved EEPROM values. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void saveToEEPROM();

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t P1_PushButton_PIN_D2 = 2;

/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t AI1_Potentiometer_Vout_PIN_A1 = A1;
const uint8_t AI2_Potentiometer_Vout_PIN_A0 = A0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(P1_PushButton_PIN_D2);

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(P1_PushButton_PIN_D2, INPUT_PULLUP);
    pinMode(AI1_Potentiometer_Vout_PIN_A1, INPUT);
    pinMode(AI2_Potentiometer_Vout_PIN_A0, INPUT);

    Serial.begin(115200);
    Serial.println();
    Serial.println(">>> EEPROM Example <<<");

    button.begin();
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    button.read();

    // Check if pushbutton P1 is pressed
    if (button.isPressed())
    {
        // Read values of AI1 and AI2
        int ai1Value = analogRead(AI1_Potentiometer_Vout_PIN_A1);
        int ai2Value = analogRead(AI2_Potentiometer_Vout_PIN_A0);

        // Save values to EEPROM
        EEPROM.put(0, ai1Value);
        EEPROM.put(sizeof(int), ai2Value);
    }
    else
    {
        // Check if pushbutton P1 is released
        if (button.isReleased())
        {
            // Stop reading values of AI1 and AI2
            button.disableInterrupt();
        }

        // Print saved EEPROM values
        int ai1Value;
        int ai2Value;
        EEPROM.get(0, ai1Value);
        EEPROM.get(sizeof(int), ai2Value);
        Serial.print("AI1 Value: ");
        Serial.println(ai1Value);
        Serial.print("AI2 Value: ");
        Serial.println(ai2Value);
    }
}