Skip to content

Commit

Permalink
single led colour change
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuna Iwata authored and Yuna Iwata committed Nov 18, 2022
1 parent c536e70 commit 68bf777
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyserial
15 changes: 15 additions & 0 deletions serial_send_LED.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import serial.tools.list_ports

ports = serial.tools.list_ports.comports()
serialInst = serial.Serial()

serialInst.baudrate = 9600
serialInst.port = '/dev/cu.usbmodem1401'
serialInst.open()

while True:
command = input("LED pink/red/green? invalid response will show blue bc why not: ")
serialInst.write(command.encode('utf-8'))

if command =='exit':
exit()
57 changes: 57 additions & 0 deletions sketch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const int greenLEDPin = 9;
const int redLEDPin = 11;
const int blueLEDPin = 10;



void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);

}

void loop() {


if (Serial.available()>0){
String msg = Serial.readString();

if(msg == "pink"){
RGB_color(255, 255, 125); // Rasp
} else if (msg == "red"){
RGB_color(255, 0, 0); // Red
} else if (msg == "green"){
RGB_color(0, 255, 0); //Green
} else {
RGB_color(0, 0, 255);
}
}
// put your main code here, to run repeatedly:
// RGB_color(255, 0, 0); // Red
// delay(1000);
// RGB_color(0, 255, 0); // Green
// delay(1000);
// RGB_color(0, 0, 255); // Blue
// delay(1000);
// RGB_color(255, 255, 125); // Raspberry
// delay(1000);
// RGB_color(0, 255, 255); // Cyan
// delay(1000);
//RGB_color(255, 0, 255); // Magenta
// delay(1000);
// RGB_color(255, 255, 0); // Yellow
// delay(1000);
//RGB_color(255, 255, 255); // White
// delay(1000);
}

void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(redLEDPin, red_light_value);
analogWrite(greenLEDPin, green_light_value);
analogWrite(blueLEDPin, blue_light_value);
}

0 comments on commit 68bf777

Please sign in to comment.