Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 3 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
|
Hi! I made this project for fun. The rgb led is controlled via angraphical user interface. You can change the code to change the colour of the led or make diffrent patterns of lighthing or make a more friendly user interface. I will add new things soon. Hope you enjoy! Leave a like and a comment :)
# hope you enjoy it and Merry X-mas :)
import serial
import tkinter
import tkinter.messagebox
arduinoData = serial.Serial('com7',9600)
def led_rosu():
arduinoData.write(b'0')
def led_verde():
arduinoData.write(b'1')
def led_albas():
arduinoData.write(b'2')
def led_alb():
arduinoData.write(b'3')
def led_vio():
arduinoData.write(b'4')
def led_random():
arduinoData.write(b'5')
# MAIN
ledrgb = tkinter.Tk()
ledrgb.title("Arduino RGB Led Control")
ledrgb.configure(background="grey")
tkinter.messagebox.showinfo("X","!!! Bun venit !!!")
#exit function
def close_window():
arduinoData.write(b'0')
ledrgb.destroy()
exit()
Button = tkinter.Button
#just a few buttons
btn1 = Button(ledrgb, text="Rosu",bg="red",fg="white",command = led_rosu)
btn2 = Button(ledrgb, text="Verde",bg="red",fg="white",command = led_verde)
btn3 = Button(ledrgb, text="Albastru",bg="red",fg="white",command = led_albas)
btn4 = Button(ledrgb, text="Alb", command = led_alb)
btn5 = Button(ledrgb, text="Violet", command = led_vio)
btn6 = Button(ledrgb, text="Random", command=led_random)
btn7 = Button(ledrgb, text="Exit", command=close_window) .grid(row=3)
btn1.grid(row=0,column=1)
btn2.grid(row=0,column=2)
btn3.grid(row=1,column=1)
btn4.grid(row=1,column=2)
btn5.grid(row=2,column=1)
btn6.grid(row=2,column=2)
#good luck
ledrgb.mainloop()
// FeBe noi.2018
// control led rgb prin python tkinter
// fisierul rgb_buc.py
char serialData;
//check always the pins
int redPin= 7;
int greenPin = 6;
int bluePin = 5;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int valoareIluminare = analogRead(0);
Serial.println(valoareIluminare, DEC);
delay(100);
/*
for (int i = 0 ; i < 256; i++) {
setColor(i, i, 0);
delay(100);
}
setColor(0, 0, 255); // Blue Color
delay(1000);
delay(500);
delay(1000);
setColor(100, 100, 100);
delay(1500);
setColor(100,0,200);
delay(2000);
*/
if (Serial.available() > 0) {
serialData = Serial.read();
Serial.print(serialData);
if(serialData == '0') {
setColor(255, 0, 0); // Red Color
} else if (serialData == '1') {
setColor(0, 255, 0); // Green Color
} else if (serialData == '2') {
setColor(0, 0, 255); // Blue Color
} else if (serialData == '3') {
setColor(255, 255, 255); // White Color
} else if (serialData == '4') {
setColor(170, 0, 255); // Purple Color
} else if (serialData == '5') {
// int rint = random(1,255);
// int rrnt = random(1,255);
// int rtnt = random(1,255);
// for (int i = 255; i>0; i--){
// setColor(0, i, 0);
// delay(5);
// }
// setColor(rint, rrnt, rtnt);
/* delay(2000);
setColor(rrnt, rtnt, rtnt);
}*/
}
}
}
//rgb
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
Comments