Wednesday, October 24, 2007

Blink LED with MYSQL


using a data set from http://www.dec.ny.gov/airmon/index.php

We are not allowed back end access to the websites data however, we did devise a way for importing the data downloaded off the site into our own mysql data base. that can then be used to control a led on our breadboard.

The processing script will find the data on the internet download it into an array and then cycle through that array sending out each value to the micro controller through the serial port. the micro controller then reads the output from the PC and determines if it is over a certain threshold. If the value is greater than the threshold it will turn on the led and if the output is bellow a certain threshold it will turn the led off.

Processing script:

import de.bezier.sql.*;
import de.bezier.mysql.*;

import processing.serial.*;


MySQL msql;

Serial myPort;

String table = "airTest";
String[] si = new String[636];

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

println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 2400);



msql = new MySQL( "SQL06.FREEMYSQL.NET", "ecovis", "fbitonti", "housebed202", this );

if ( msql.connect() )
{
// create a table with an id and a word
//
msql.execute( "CREATE TABLE IF NOT EXISTS " + table + " ("+
"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"+
"word VARCHAR( 255 )"+
")"
);




msql.query( "SELECT * FROM " + table );

int scount = 0;
while (msql.next())
{
String s = msql.getString("word");
si[scount] = s;
int n = msql.getInt("id");
println(s + " " + n);
float f = float(s);


scount = scount + 1;
}

// need to find out how many rows there are in table?
//
msql.query( "SELECT COUNT(*) FROM " + table );
msql.next();
println( "number of rows: " + msql.getInt(1) );
}
else
{
// connection failed !
}


}

void draw()
{

int gg = 0;

while(gg < f =" int(si[gg]);">0){

delay(1000);
println("port");
println(myPort.available());

if (myPort.available() == 0) {
delay(1000);
int x = int(si[gg]);
println(x);
myPort.write(x);
println("value");
println(si[gg]);
gg = gg + 1;
// myPort.stop();


}

myPort.clear();
delay(1000);
}

}
}

pbasic Script:

' {$STAMP BS2}
' {$PBASIC 2.5}

check VAR Byte
proIn VAR Byte

Main:
DO
check = IN3
proIn = IN10

SERIN 16, 16780, [proIn]
IF proIn <> 13 THEN
LOW 14
ENDIF


LOOP
END



Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?