Devices & Components
Arduino Uno Rev3
Rezistors
10kOhm potentiometer
Switch
RGB LED or RGB LED Module
Software & Tools
Arduino IDE
Project description
Code
RGB LED
cpp
Changing the brightness of individual colors
1// RGB LED 2// Tom´s microscope under LED 3 4/*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/ 5const int redPin = 11; // číslo pinu červené barvy 6const int greenPin = 10; // číslo pinu zelené barvy 7const int bluePin = 9; // číslo pinu modré barvy 8const int pinbutton = 2; 9const int pot = A0; 10float val=0; 11byte hodnota=0; 12 13void setup() { 14pinMode(redPin, OUTPUT); // nastavení pinu redPin jako výstupu 15pinMode(greenPin, OUTPUT); // nastavení pinu greenPin jako výstupu 16pinMode(bluePin, OUTPUT); // nastavení pinu bluePin jako výstupu 17pinMode(pinbutton, INPUT); 18pinMode(pot, INPUT); 19analogWrite(redPin, 255); 20analogWrite(greenPin, 255); 21analogWrite(bluePin, 255); 22} 23 24void loop() { 25 26while (digitalRead(pinbutton) == LOW) { 27val = analogRead(pot); 28hodnota = (val/1024)*255; 29analogWrite(redPin, hodnota);}; 30delay(2000); 31 32while (digitalRead(pinbutton) == LOW) { 33val = analogRead(pot); 34hodnota = (val/1024)*255; 35analogWrite(greenPin, hodnota);}; 36delay(2000); 37 38while (digitalRead(pinbutton) == LOW) { 39val = analogRead(pot); 40hodnota = (val/1024)*255; 41analogWrite(bluePin, hodnota);}; 42delay(2000); 43}
Comments
Only logged in users can leave comments