Advertisement
pleasedontcode

testbutton1 rev_01

Dec 6th, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: testbutton1
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2023-12-06 09:15:32
  15.     - Source Code generated by: Jordan
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.     /* turns on and off bright orange */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <EasyButton.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t myButton_PushButton_PIN_D2 = 2;
  34. const uint8_t ledPin = 13; // Pin for the bright orange LED
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. EasyButton myButton(myButton_PushButton_PIN_D2);
  38.  
  39. void setup(void)
  40. {
  41.   // put your setup code here, to run once:
  42.   pinMode(myButton_PushButton_PIN_D2, INPUT_PULLUP);
  43.   pinMode(ledPin, OUTPUT); // Set the LED pin as output
  44.  
  45.   // Initialize the EasyButton library with the pin
  46.   myButton.begin();
  47. }
  48.  
  49. void loop(void)
  50. {
  51.   // put your main code here, to run repeatedly:
  52.  
  53.   // Read the button state
  54.   myButton.read();
  55.  
  56.   // Check if the button is pressed
  57.   if (myButton.isPressed())
  58.   {
  59.     // Button is pressed
  60.     digitalWrite(ledPin, HIGH); // Turn on the LED
  61.   }
  62.   else
  63.   {
  64.     // Button is released
  65.     digitalWrite(ledPin, LOW); // Turn off the LED
  66.   }
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement