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: **Color Control** - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-11-27 10:40:23 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Photoresistor and rgb led with 5 colours */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include
#include
#include
/****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(); // Added prototype for updateOutputs function void colours(int R_value, int G_value, int B_value); // Added prototype for colours function /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t Photoresistorandrgbled_LEDRGB_Red_PIN_D2 = 2; const uint8_t Photoresistorandrgbled_LEDRGB_Green_PIN_D3 = 3; const uint8_t Photoresistorandrgbled_LEDRGB_Blue_PIN_D4 = 4; // USER CODE PINS const uint8_t RED_PIN = 9; // Changed variable name for clarity const uint8_t GREEN_PIN = 10; // Changed variable name for clarity const uint8_t BLUE_PIN = 11; // Changed variable name for clarity const uint8_t LDR_PIN = A0; // Changed variable name for clarity /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool Photoresistorandrgbled_LEDRGB_Red_PIN_D2_rawData = 0; bool Photoresistorandrgbled_LEDRGB_Green_PIN_D3_rawData = 0; bool Photoresistorandrgbled_LEDRGB_Blue_PIN_D4_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float Photoresistorandrgbled_LEDRGB_Red_PIN_D2_phyData = 0.0; float Photoresistorandrgbled_LEDRGB_Green_PIN_D3_phyData = 0.0; float Photoresistorandrgbled_LEDRGB_Blue_PIN_D4_phyData = 0.0; int LDRvalue = 0; // Added variable for LDR value void setup(void) { // put your setup code here, to run once: pinMode(Photoresistorandrgbled_LEDRGB_Red_PIN_D2, OUTPUT); pinMode(Photoresistorandrgbled_LEDRGB_Green_PIN_D3, OUTPUT); pinMode(Photoresistorandrgbled_LEDRGB_Blue_PIN_D4, OUTPUT); // USER CODE SETUP Serial.begin(9600); pinMode(RED_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: updateOutputs(); // Refresh output data // USER CODE LOGIC LDRvalue = analogRead(LDR_PIN); // Read the LDR value if (LDRvalue < 250) { digitalWrite(RED_PIN, HIGH); delay(300); } else { digitalWrite(RED_PIN, LOW); } Serial.print("Photoresistor value: "); Serial.println(LDRvalue); delay(100); colours(255, 0, 0); // RED delay(1000); colours(0, 255, 0); // GREEN delay(1000); colours(0, 0, 255); // BLUE delay(1000); colours(255, 0, 255); // MAGENTA delay(1000); colours(255, 255, 0); // YELLOW delay(1000); } void updateOutputs() { digitalWrite(Photoresistorandrgbled_LEDRGB_Red_PIN_D2, Photoresistorandrgbled_LEDRGB_Red_PIN_D2_rawData); digitalWrite(Photoresistorandrgbled_LEDRGB_Green_PIN_D3, Photoresistorandrgbled_LEDRGB_Green_PIN_D3_rawData); digitalWrite(Photoresistorandrgbled_LEDRGB_Blue_PIN_D4, Photoresistorandrgbled_LEDRGB_Blue_PIN_D4_rawData); } void colours(int R_value, int G_value, int B_value) { analogWrite(RED_PIN, R_value); analogWrite(GREEN_PIN, G_value); analogWrite(BLUE_PIN, B_value); } /* END CODE */
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)