/*   simple-installation.c
     colby leider

     code to run a simple installation that responds to ambient light and
       and temperature.
     assumes a photoresistor is connected to analog port 6 and that a
       thermistor is connected to analog port 0
     scale and offset values for the sensor voltages will have to be
       changed dependent on the characteristics of the sensors used.
 */


void main() {
   int last1, last2, current1, current2, temp;

   turbo_on();
    
   while (!start_button());
   init_sci();
   
   last1 = 0;
   current1 = 0;
   last2 = 0;
   current2 = 0;
    
   while (1) {
       current1 = (110 - analog(6));
       temp = analog(0);
       if ((last1 - current1 > 1) && current1 > 40 && current1 < 100) {
         note_on(14, current1, temp);
       }
       last1 = current1;
       
       current2 = analog(0) * 2 - 300;
       if (last2 - current2 > 2) {
           note_off(14, last2);
           note_on(14, current2, temp);
       }
       last2 = current2;
       sleep(0.005 + (float)knob()*0.001);
   }
}
