I have got a working version of the twitter bot.
Every 60 seconds it will grab the latest tweet to me and if it contains a html colour code it will change my LEDs to that colour.
Python
from twython import Twython, TwythonError
import serial, time, re
ser = serial.Serial('COM3', 9600, timeout=2)
regex = re.compile('(#[a-f0-9]{6}|#[a-f0-9]{3})', re.IGNORECASE)
api_key = ""
api_secret = ""
access_token = ""
access_secret = ""
tweetID = 0
twitter = Twython(api_key, api_secret, access_token, access_secret)
while True:
try:
search_results = twitter.search(q = 'to:joshuarickers', count = 1, since_id = tweetID)
except TwythonError as e:
print(e)
print('Tweet: ', search_results['statuses'][0]['text'])
if re.search(regex, search_results['statuses'][0]['text']):
colour = re.search(regex, search_results['statuses'][0]['text']).group()
print('Colour :', colour)
print(ser.readline())
ser.write(bytes(colour, 'ascii'))
time.sleep(60)
Arduino
#include "FastLED.h"
#define NUM_LEDS 50
#define DATA_PIN 11
#define CLOCK_PIN 13
CRGB leds[NUM_LEDS];
String htmlColour;
long number;
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
}
void loop(){
if (Serial.available() > 0){
htmlColour = Serial.readStringUntil('\n');
Serial.read();
number = strtol( &htmlColour[1], NULL, 16);
Serial.println(number);
}
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = number;
leds[i].maximizeBrightness();
}
FastLED.show();
}