/** * Energy meter */ int scrWidth = 12*24*2; int scrHeight = 240; int binIs = 0; // current bin to increment (1 of 12*24) int[] dataCollection = new int[12*24]; // 24 hours x 12 bins per hour (1 every 5 mins) int MPosX = 0; // position of mouse within data window String HoursS = ""; String MinsS = ""; void setup() { size(scrWidth, scrHeight); noStroke(); smooth(); rectMode(CORNER); noFill(); background(0); // clear (black) background PFont font; font = loadFont("ArialMT-14.vlw"); textFont(font); } void draw() { int last24h = 0; binIs = hour()*12+minute()/5; if((second() == 0) && (5*(minute()/5) == minute())){ dataCollection[binIs] = 0; // initialize bin to zero (write over every 24 hours) println("Time is "+hour()+":"+minute()); // print time every 5 minutes } background(0); // clear (black) background stroke(255, 255, 255, 255); for (int x = 0; x < 24*12; x++){ line(2*x,scrHeight,2*x,scrHeight-dataCollection[x]); } for (int x = 0; x < 24*12; x++){ // evaluate last 24h cumulative last24h += dataCollection[x]; } MPosX = mouseX/2; if (MPosX >= 12*24) MPosX = 12*24-1; text(nf(MPosX/12,2)+":"+nf(5*(MPosX%12),2)+" kWh "+float(dataCollection[MPosX])/1000+" last 24 hours : kWh "+float(last24h)/1000,5,14); } void mousePressed() { dataCollection[binIs]++; }