/*
* DA shower
* measure on analog 0
* print ----------*------ on tty @ 115200 
* Quantified with OSC_STEPs
* commands:
*  + increase looptime by STEP(10) msec
*  - decrease ....
*  ? increase   "*10" step above
*  _ decrease   ...
*/


void setup()
{
 Serial.begin(115200);
 int i;
}

#define STEP 10
#define OSC_STEP 32
int ad,i,step=16;
int dly=0;
char fl,ch;

void gui()
{
  if (Serial.available())
 {
   ch = Serial.read();
   switch (ch)
   {
     case '+': dly +=STEP; 
       Serial.print("Delay(msek) ");
       Serial.println(dly);
       delay(500);
     break;
     case '?': dly +=10*STEP; 
       Serial.print("Delay(msek) ");
       Serial.println(dly);
       delay(500);
     break;
     case '-': if (STEP <= dly) dly -=STEP; 
       Serial.print("Delay(msek) ");
       Serial.println(dly);
       delay(500);
       break;
     case '_': if (STEP <= dly) dly -=10*STEP; 
       Serial.print("Delay(msek) ");
       Serial.println(dly);
       delay(500);
       break;
     case '0': dly = 0; // reset
    default:; 
   }
 }
}
void loop()
{ 
  ad = analogRead(0);
 
 fl = 0;
 for (i=0; i <= 1024; i+=OSC_STEP)
 {
   if (i < ad )
     Serial.print("-");
   else {
     if (!fl) {
        Serial.print("*");
        fl = 1;
     }
     else {
     Serial.print("-");
     }
   }
 }
 Serial.println(" ");
 gui();
 delay(dly);
 } 
