Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: **Game Interface**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-02-22 15:10:52
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The LCD shows a random target (100-900). Adjust */
- /* the potentiometer to match it. A 10s timer starts. */
- /* Press the button to check. If matched, "You Win!" */
- /* Else, "Try Again!" If time runs out, "Time's Up!" */
- /* Press to restart. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <LiquidCrystal.h> //https://github.com/arduino-libraries/LiquidCrystal
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Button_PushButton_PIN_D2 = 2;
- const uint8_t buttonPin = 6; // button pin
- /***** DEFINITION OF ANALOG INPUT PINS *****/
- const uint8_t Buzzer_Potentiometer_Vout_PIN_A0 = A0;
- const uint8_t potPin = A0; // potentiometer pin (this is already defined above)
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Leds_LED_PIN_D3 = 3;
- const uint8_t Standard_LCD1602_D5_PIN_D7 = 7; // buzzer pin is defined below
- const uint8_t Passive_PassiveBuzzer_Signal_PIN_D10 = 10;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool Leds_LED_PIN_D3_rawData = 0;
- bool Standard_LCD1602_D5_PIN_D7_rawData = 0;
- bool Passive_PassiveBuzzer_Signal_PIN_D10_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float Leds_LED_PIN_D3_phyData = 0.0;
- float Standard_LCD1602_D5_PIN_D7_phyData = 0.0;
- float Passive_PassiveBuzzer_Signal_PIN_D10_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize the LCD pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // This line is compatible with the LiquidCrystal library
- int targetValue; // variable to store the target value
- int currentValue; // variable to store the current value of the potentiometer
- int buzzerPin = 7; // buzzer pin (this conflicts with Standard_LCD1602_D5_PIN_D7)
- int timer = 10000; // timer in milliseconds
- unsigned long startTime; // variable to store the start time of the game
- bool gameStarted = false; // variable to track if the game has started
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Button_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(Buzzer_Potentiometer_Vout_PIN_A0, INPUT);
- pinMode(Leds_LED_PIN_D3, OUTPUT);
- pinMode(Standard_LCD1602_D5_PIN_D7, OUTPUT);
- pinMode(Passive_PassiveBuzzer_Signal_PIN_D10, OUTPUT);
- // USER CODE START
- lcd.begin(16, 2); // initialize the LCD with 16 columns and 2 rows
- randomSeed(analogRead(0)); // seed the random number generator with a random value from the potentiometer
- targetValue = random(100, 900); // generate a random target value between 100 and 900
- lcd.print("Target: "); // print the target label on the LCD
- lcd.print(targetValue); // print the target value on the LCD
- pinMode(buttonPin, INPUT); // set the button pin as input
- pinMode(buzzerPin, OUTPUT); // set the buzzer pin as output
- // USER CODE END
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // USER CODE START
- if (!gameStarted) { // if the game has not started
- currentValue = analogRead(potPin); // read the current value of the potentiometer
- lcd.setCursor(0, 1); // set the cursor to the second row of the LCD
- lcd.print("Current: "); // print the current label on the LCD
- lcd.print(currentValue); // print the current value on the LCD
- }
- if (digitalRead(buttonPin) == HIGH) { // if the button is pressed
- if (gameStarted) { // check if the game has started
- if (currentValue == targetValue) { // if the current value matches the target value
- lcd.clear(); // clear the LCD
- lcd.print("You Win!"); // print "You Win!" on the LCD
- digitalWrite(buzzerPin, HIGH); // turn on the buzzer
- delay(1000); // wait for 1 second
- digitalWrite(buzzerPin, LOW); // turn off the buzzer
- } else { // if the current value does not match the target value
- lcd.clear(); // clear the LCD
- lcd.print("Try Again!"); // print "Try Again!" on the LCD
- }
- gameStarted = false; // set gameStarted to false to start a new game
- } else { // if the game has not started
- startTime = millis(); // store the current time as the start time
- gameStarted = true; // set gameStarted to true to indicate the game has started
- }
- }
- if (gameStarted && (millis() - startTime >= timer)) { // if the timer has run out
- lcd.clear(); // clear the LCD
- lcd.print("Time's Up!"); // print "Time's Up!" on the LCD
- gameStarted = false; // set gameStarted to false to start a new game
- }
- // USER CODE END
- }
- void updateOutputs()
- {
- digitalWrite(Leds_LED_PIN_D3, Leds_LED_PIN_D3_rawData);
- digitalWrite(Standard_LCD1602_D5_PIN_D7, Standard_LCD1602_D5_PIN_D7_rawData);
- digitalWrite(Passive_PassiveBuzzer_Signal_PIN_D10, Passive_PassiveBuzzer_Signal_PIN_D10_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement