Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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: "Proximity-controlled Outputs" - Source Code compiled for: Arduino Uno - Source Code created on: 2024-04-10 01:57:07 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* f no object is within range of the sensor, the LED */ /* is not lit. • If an object is between 5 and 20 cm */ /* away from the sensor, the LED blinks 5 times per */ /* second. • If an object is between 20 cm and 30 cm */ /* away from the sensor, the LED is lit */ /****** SYSTEM REQUIREMENT 2 *****/ /* f no object is within range of the sensor, the LED */ /* is not lit. • If an object is between 5 and 20 cm */ /* away from the sensor, the LED blinks 5 times per */ /* second. • If an object is between 20 cm and 30 cm */ /* away from the sensor, the LED is lit */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
/****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t IRsensor_LED_PIN_D2 = 2; const uint8_t led_LED_PIN_D3 = 3; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool IRsensor_LED_PIN_D2_rawData = 0; bool led_LED_PIN_D3_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float IRsensor_LED_PIN_D2_phyData = 0.0; float led_LED_PIN_D3_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ IRSense sensor1; void setup(void) { // put your setup code here, to run once: Wire.begin(); sensor1.begin(Wire); pinMode(IRsensor_LED_PIN_D2, OUTPUT); pinMode(led_LED_PIN_D3, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: updateOutputs(); // Refresh output data delay(200); // Delay for 200ms } void updateOutputs(void) { int proximity = sensor1.readProximity(); if (proximity >= 500 && proximity <= 2000) // Object is between 5cm and 20cm { IRsensor_LED_PIN_D2_rawData = !IRsensor_LED_PIN_D2_rawData; // Toggle the LED state at 5 times per second } else if (proximity > 2000 && proximity <= 3000) // Object is between 20cm and 30cm { IRsensor_LED_PIN_D2_rawData = HIGH; // Turn on the LED } else { IRsensor_LED_PIN_D2_rawData = LOW; // Turn off the LED } digitalWrite(IRsensor_LED_PIN_D2, IRsensor_LED_PIN_D2_rawData); digitalWrite(led_LED_PIN_D3, led_LED_PIN_D3_rawData); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)