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: Pin Monitor
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-12-30 15:17:26
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Create a requirement for monitoring the digital */
- /* input pin D2 (connected to an RC component) to */
- /* detect voltage changes, triggering an LED */
- /* indicator when the button is pressed or released. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // Include the necessary libraries
- #include <Arduino.h>
- // Define pin numbers
- const int inputPin = 2; // Digital pin D2 connected to the RC component
- const int ledPin = 13; // Onboard LED indicator
- // Variable to store the current state of the input pin
- int inputState = LOW;
- // Variable to store the previous state of the input pin
- int prevInputState = LOW;
- void setup() {
- // Initialize the input pin as an input with internal pull-down resistor
- pinMode(inputPin, INPUT); // For some boards, this defaults to internal pull-up
- // Initialize the LED pin as an output
- pinMode(ledPin, OUTPUT);
- // Start serial communication for debugging
- Serial.begin(9600);
- }
- void loop() {
- // Read the current state of the input pin
- inputState = digitalRead(inputPin);
- // Check if the state has changed from the previous loop
- if (inputState != prevInputState) {
- // Update the LED based on the input state
- if (inputState == HIGH) {
- digitalWrite(ledPin, HIGH); // Turn on LED
- Serial.println("Button pressed or voltage detected")
- } else {
- digitalWrite(ledPin, LOW); // Turn off LED
- Serial.println("Button released or voltage lost")
- }
- // Save the current state as previous state for next iteration
- prevInputState = inputState;
- }
- // Small delay to debounce or reduce CPU usage
- delay(50);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment