14.11.08

looking at twitter

I've now got a piece of code that looks at a twitter feed and sends that information to an arduino board:

arduino code:

//getting it to keep one light lit up

int timer = 10000000; // The higher the number, the slower the timing.
int happy[] = { 6, 7,}; // an array of pin numbers
int spiffing[] = { 8, 9 };
int num_pins = 6; // the number of pins (i.e. the length of the array)
int val;

void setup()
{
Serial.begin(9600);

int i;

for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
pinMode(happy[i], OUTPUT); // set each pin as an output
pinMode(spiffing[i], OUTPUT);
}

void loop()
{
int i;

if (Serial.available()) {
val = Serial.read();
if (val == 'A') {
digitalWrite(happy[i], HIGH);
}
else {
digitalWrite(happy[i], LOW);
}


if (val == 'B') {
digitalWrite(spiffing[i], HIGH);
}
else {
digitalWrite(spiffing[i], LOW);
}
}
}


processing code:

//finds a word, sends a signal to the lilypad then stops the loop.

import processing.serial.*;

Serial port;

String[] tokens; //array
int counter;

void setup() {
size(100, 100);

println(Serial.list());
port = new Serial(this,Serial.list()[0], 9600);

//load file and split up words
String[] lines = loadStrings("http://twitter.com/allemotional");
String allText = join(lines, " ");
tokens = splitTokens(allText, " ,.?!:;[]-");

}

//so it's now pulling in that sentence and splitting it up.

void draw() {
background(255);
fill(0);

String s = tokens[counter];
counter = (counter +1) % tokens.length;
//look at the words one at a time please



//is the word there?
if (s.equals("happy")) {
println("happy");
port.write('A');
noLoop(); //DON'T LOOP IT BAHBEE.


}

if (s.equals("spiffing")) {
println("spiffing");
port.write('B');
noLoop(); //DON'T LOOP IT BAHBEE.

}

}


it's not perfect. i just need to sort out a way of getting the program to delay then restart after finding a word. That piece of code is eluding me at the moment.

No comments: