Advertisement
pleasedontcode

project12 rev_01

Nov 21st, 2023
61
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: project12
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-21 14:34:49
  15.     - Source Code generated by: Mohammad Ayman
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* Turn on the 6 LED Lights when the object is near */
  24. /* 20cm in Ultrasonic sensor and on the 2 Snoozers */
  25. /* also */
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void buttonPressed(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t myButton_Pin = 2;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. EasyButton myButton(myButton_Pin);
  37.  
  38. /****** DEFINITION OF LED PINS *****/
  39. const uint8_t ledPin1 = 3;
  40. const uint8_t ledPin2 = 4;
  41. const uint8_t ledPin3 = 5;
  42. const uint8_t ledPin4 = 6;
  43. const uint8_t ledPin5 = 7;
  44. const uint8_t ledPin6 = 8;
  45.  
  46. /****** DEFINITION OF SNOOZER PINS *****/
  47. const uint8_t snoozerPin1 = 9;
  48. const uint8_t snoozerPin2 = 10;
  49.  
  50. void setup(void)
  51. {
  52.     // Initialize Serial for debugging purposes.
  53.     Serial.begin(115200);
  54.  
  55.     // Initialize the button.
  56.     myButton.begin();
  57.  
  58.     // Set the callback function for button pressed event.
  59.     myButton.onPressed(buttonPressed);
  60.  
  61.     // Set LED pins as output
  62.     pinMode(ledPin1, OUTPUT);
  63.     pinMode(ledPin2, OUTPUT);
  64.     pinMode(ledPin3, OUTPUT);
  65.     pinMode(ledPin4, OUTPUT);
  66.     pinMode(ledPin5, OUTPUT);
  67.     pinMode(ledPin6, OUTPUT);
  68.  
  69.     // Set snoozer pins as output
  70.     pinMode(snoozerPin1, OUTPUT);
  71.     pinMode(snoozerPin2, OUTPUT);
  72. }
  73.  
  74. void loop(void)
  75. {
  76.     // Read the button state.
  77.     myButton.read();
  78.  
  79.     // put your main code here, to run repeatedly:
  80. }
  81.  
  82. void buttonPressed()
  83. {
  84.     // Turn on the 6 LED Lights when the object is near 20cm in Ultrasonic sensor and the 2 Snoozers also
  85.     digitalWrite(ledPin1, HIGH);
  86.     digitalWrite(ledPin2, HIGH);
  87.     digitalWrite(ledPin3, HIGH);
  88.     digitalWrite(ledPin4, HIGH);
  89.     digitalWrite(ledPin5, HIGH);
  90.     digitalWrite(ledPin6, HIGH);
  91.  
  92.     digitalWrite(snoozerPin1, HIGH);
  93.     digitalWrite(snoozerPin2, HIGH);
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement