-
-
Save MatthewScholefield/06b028c4b542f27a1e789c50c5b67551 to your computer and use it in GitHub Desktop.
Python + Arduino on/off the LED.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LED 9 | |
void setup() { | |
pinMode(LED, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (Serial.available()) { | |
int brightness = (int)Serial.parseInt(); | |
if (brightness > 255) { | |
brightness = 255; | |
else if (brightness < 0) { | |
brightness = 0; | |
} | |
analogWrite(LED, brightness); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial # you need to install the pySerial :pyserial.sourceforge.net | |
import time | |
with open('RMS_EMG.txt') as f: | |
lines = f.read().split('\n') | |
arduino = serial.Serial('/dev/tty.usbserial', 9600) | |
for line in lines: | |
brightness = int(float(line.split(',')[-1]) * 255) | |
arduino.write(bytes(str(brightness), 'ascii')) | |
time.sleep(1/100.) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment