pleasedontcode

Pin Monitor rev_01

Dec 30th, 2025
25
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: Pin Monitor
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-12-30 15:17:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create a requirement for monitoring the digital */
  21.     /* input pin D2 (connected to an RC component) to */
  22.     /* detect voltage changes, triggering an LED */
  23.     /* indicator when the button is pressed or released. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. // Include the necessary libraries
  30. #include <Arduino.h>
  31.  
  32. // Define pin numbers
  33. const int inputPin = 2; // Digital pin D2 connected to the RC component
  34. const int ledPin = 13; // Onboard LED indicator
  35.  
  36. // Variable to store the current state of the input pin
  37. int inputState = LOW;
  38. // Variable to store the previous state of the input pin
  39. int prevInputState = LOW;
  40.  
  41. void setup() {
  42.   // Initialize the input pin as an input with internal pull-down resistor
  43.   pinMode(inputPin, INPUT); // For some boards, this defaults to internal pull-up
  44.   // Initialize the LED pin as an output
  45.   pinMode(ledPin, OUTPUT);
  46.   // Start serial communication for debugging
  47.   Serial.begin(9600);
  48. }
  49.  
  50. void loop() {
  51.   // Read the current state of the input pin
  52.   inputState = digitalRead(inputPin);
  53.   // Check if the state has changed from the previous loop
  54.   if (inputState != prevInputState) {
  55.     // Update the LED based on the input state
  56.     if (inputState == HIGH) {
  57.       digitalWrite(ledPin, HIGH); // Turn on LED
  58.       Serial.println("Button pressed or voltage detected")
  59.     } else {
  60.       digitalWrite(ledPin, LOW); // Turn off LED
  61.       Serial.println("Button released or voltage lost")
  62.     }
  63.     // Save the current state as previous state for next iteration
  64.     prevInputState = inputState;
  65.   }
  66.   // Small delay to debounce or reduce CPU usage
  67.   delay(50);
  68. }
  69.  
  70. /* END CODE */
  71.  
Advertisement
Add Comment
Please, Sign In to add comment