// // phototransistor input to historical graph // // Blair Evans // // based on c code by // Neil Gershenfeld // 10/27/10 // // (c) Massachusetts Institute of Technology 2010 // Permission granted for experimental and personal use; // license for commercial sale available from MIT. // const byte photoPin = A5; // Phototransitor const int led_delay = 1000; // LED delay of 1 ms /* SV2 */ const byte A = 3; // row 1 const byte B = 4; // row 2 const byte C = 5; // row 3 const byte D = 6; // row 4 const byte E = 7; // row 5 byte anodes1[] = {E,E,E,E,D}; byte anodes2[] = {D,D,D,C,C}; byte anodes3[] = {C,C,B,B,B}; byte anodes4[] = {B,A,A,A,A}; byte cathodes[] = {A,B,C,D,E}; float eps = 1; float bar1; float bar2; float bar3; float bar4; int hist[] = {0,0,0,0}; int disp_count = 0; int photoValue; byte state = LOW; void flash(uint8_t from, uint8_t to, uint8_t delay) { // // source from, sink to, flash // static int i; digitalWrite(from,HIGH); //set(led_port,from); digitalWrite(to,LOW); //clear(led_port,to); pinMode(from,OUTPUT); //output(led_direction,from); pinMode(to,OUTPUT); //output(led_direction,to); for (i = 0; i < delay; ++i) delayMicroseconds(led_delay); pinMode(from,INPUT); //input(led_direction,from); pinMode(to,INPUT); // input(led_direction,to); } void setup() { Serial.begin(57600); pinMode(13, OUTPUT); } void loop() { int val; int i; photoValue = analogRead(photoPin); bar4 = (1-eps)*bar4 + eps*photoValue; if (state == LOW){ state = HIGH; } else { state = LOW; } digitalWrite(13,state); if (disp_count++ >= 5) { hist[3] = hist[2]; hist[2] = hist[1]; hist[1] = hist[0]; hist[0] = int((1023-bar4)/256); // 0 to 4 value disp_count = 0; } flash(anodes4[hist[0]],cathodes[hist[0]], 4); flash(anodes3[hist[1]],cathodes[hist[1]], 4); flash(anodes2[hist[2]],cathodes[hist[2]], 4); flash(anodes1[hist[3]],cathodes[hist[3]], 4); /* Serial.print(bar1); Serial.print(", "); Serial.print(bar2); Serial.print(", "); Serial.print(bar3); Serial.print(", "); Serial.print(bar4); Serial.print("; "); Serial.print(hist[0]); Serial.print(", "); Serial.print(hist[1]); Serial.print(", "); Serial.print(hist[2]); Serial.print(", "); Serial.println(hist[3]); */ }