I remembered to order my RFID reader and some cards..
forgot to order the USB connector. *face palm*
So while I've been waiting for that to appear I've been working on my code, using a button based system. As any other tech I use will use the same basic way of working; something sending a signal, something waiting for a signal, and when that signal is received running the script which looks at the weather feed and spurts it out when necessary.
(Actually it works a bit more like this, pulling in the weather feed every five seconds or whatever, and saving it. Then waiting for a signal stating what weather the user wants to look at, looking at the saved weather feed, and spitting out the appropriate weather.)
I've been using arduino for this, programming my buttony lilypad to send a signal to processing. I was having a few problems at first, once the signal was sent it wouldn't stop sending it, or processing wouldn't stop reading it. New button presses weren't even registering, which confused me a bit. I did a bit of research and found out how to debounce buttons, and now it works. Once a button is pressed it will keep displaying that weather until a new button is pressed. I would like to make some kind of rest state, where if nothing is pressed something else happens, not sure how to do it, may involve timers in processing, sending a resting state from arduino just jams the signal for button presses.
That might not make sense to you, but makes perfect sense to me. Here's the arduino code I'm currently using:
// edited the example to use two buttons
//edited the example further t o send a signal to processing.
//and debounce code from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241461190
int ledPin = 13; // LED is connected to digital pin 13
int switchPin = 2; // switch connected to digital pin 2
int switchPin2 = 5;
int switchValue; // a variable to keep track of when switch is pressed
#define BOUNCE_PERIOD 150
long last_read_time;
long last_value;
int val = 0;
int val2 = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(switchPin, INPUT); // sets the switchPin to be an input
digitalWrite(switchPin, HIGH); // sets the default (unpressed) state of switchPin to HIGH
pinMode(switchPin2, INPUT); // sets the switchPin to be an input
digitalWrite(switchPin2, HIGH); // sets the default (unpressed) state of switchPin to HIGH
Serial.begin(9600);
}
void loop() // run over and over again
{
// If we are past our bounce period
if (millis() - last_read_time > BOUNCE_PERIOD){
// Check the button
val = digitalRead(switchPin);
val2 = digitalRead(switchPin2);
// If the button has changed since last bounce period
if (val != last_value){
digitalWrite(ledPin,val);
if (val == LOW) Serial.print("A");
last_read_time = millis();
last_value = val;
delay(10);
}
if (val2 != last_value){
digitalWrite(ledPin,val2);
if (val2 == LOW) Serial.print("B");
last_read_time = millis();
last_value = val;
delay(10);
}
}
}
I've also been knitting my second cloud and light raindrop... the knitting never ends!!!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment