commit 1df3c70f2cd46a01bc4591577f51505f29cf65cf Author: James Devine Date: Thu Dec 26 15:53:18 2013 -0800 diff --git a/snowflake energy meter.pde b/snowflake energy meter.pde new file mode 100644 index 0000000..39589f1 --- /dev/null +++ b/snowflake energy meter.pde @@ -0,0 +1,147 @@ +//Based on an example by Tom Igoe +PrintWriter output; +import processing.serial.*; +import de.bezier.data.sql.*; +//import SQLibrary.*; // mysql database library +int xrnd = 0; +int yrnd = 0; +PFont fontA; +int xbig = 1000; +int ybig = 768; +int flakesize = 200; + +Serial myPort; // The serial port: +String buff = ""; +int NEWLINE = 10; +MySQL msql; + +void setup() { + // List all the available serial ports: + println(Serial.list()); + + // I know that the first port in the serial list on my mac + // is always my Keyspan adaptor, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + String portName = Serial.list()[1]; + myPort = new Serial(this, portName, 9600); + output = createWriter("datalog.txt"); + size(xbig,ybig); + background(0); + fontA = loadFont("CourierNew36.vlw"); + textAlign(CENTER); + textFont(fontA, 20); + + + String user = "insert username"; + String pass = "insert password"; + String database = "hackdb"; + msql = new MySQL( this, "insert yourserver here", database, user, pass ); + +} + + +void draw() +{ + while (myPort.available() > 0) + serialEvent(myPort.read()); +} + +void snowflakedraw() +{ + + //randomly refresh the screen + if (random(0,200) > 170){ +// saveFrame("snowflakespaperx##.png"); + background(0,10); + } +//stroke(0, random(50,255)); +//translate(width/2, height/2); +translate(random(0+flakesize/2,width-flakesize/2), random(0+flakesize/2,height-flakesize/2)); +rotate(radians(random(0,360))); +//float itervar = random(0, 2*width); + for (int sweep = 1; sweep 1) { + buff = buff.substring(0, buff.length()-1); + + // Parse the String into an integer. We divide by 4 because + // analog inputs go from 0 to 1023 while colors in Processing + // only go from 0 to 255. +// int val = Integer.parseInt(buff)/4; + + // Clear the value of "buff" + println(buff); + snowflakedraw(); + //xrnd = int(random(0,xbig)); + //yrnd = int(random(0,ybig)); + + + +// fill(random(180,255),random(0,255),random(0,255), 100); +// ellipse(xrnd, yrnd, 80, 80); +// font = loadFont("FFScala-32.vlw"); +// textFont(font); +// fill(random(0,50)); +// text("1kWh",xrnd-40,yrnd-5, 80, 50); + output.println(buff); + if ( msql.connect() ) + { + msql.execute(buff);//"INSERT INTO yoursqltable VALUES (55, 2, 3)"); +// msql.next(); +// (,,) +// println( "number of rows: " + msql.getInt(1) ); + } + else + { + // connection failed ! + } + buff = ""; + + // Shift over the existing values to make room for the new one. +// for (int i = 0; i < 63; i++) +// values[i] = values[i + 1]; + + // Add the received value to the array. +// values[63] = val*8; + } + } +} + +void keyPressed() { // Press a key to save the data + output.flush(); // Write the remaining data + output.close(); // Finish the file + exit(); // Stop the program +} +