#include <stdio.h>
#include <stdlib.h>
#include "binary.h"
#include <vu_meter.h>


typedef unsigned char byte;  
/* the arduino API prefers to refer to bytes rather than unsigned chars */
#define DEBOUNCE 50
#define sensorPin A7
#define button 12


byte A0 = 177;
long sensorInput = 0;
byte sensorValue = 0;

/* pseudo-boolean variables */
byte buttonState = 0;
byte VALID_TOGGLE = 1; 
byte mode = 0;

int main()
{  
  byte A0 = 177;
  long sensorInput = 0;
  byte sensorValue = 0;
  
/* pseudo-boolean variables */
  byte buttonState = 0;
  byte VALID_TOGGLE = 1; 
  byte mode = 0;
  
  /* pinMode(button, INPUT_PULLUP); */
  
  /* for (byte thisPin = 2; thisPin <= 9; thisPin++) { */
  /*   pinMode(thisPin, OUTPUT); */
  /* } */

  while (1)
    {
      sensorInput = analogRead(sensorPin);
    
      //Serial.println(sensorInput); 
      sensorValue = (sensorInput * 255) /1023; //basically arduinos own map() function with hardcoded values
      //Serial.println((int)sensorValue); 


      buttonState = digitalRead(button);
      if (buttonState == LOW && VALID_TOGGLE == 1)
	{
	  mode = !mode;
	  VALID_TOGGLE = !VALID_TOGGLE;
      
	}
      else if (buttonState == HIGH && VALID_TOGGLE == 0)
	{
	  VALID_TOGGLE = !VALID_TOGGLE;
	  delay(DEBOUNCE);
	}
  
   
 
      if (mode == 0){
	binary_value_display(sensorValue);
      }
      else if (mode == 1){
	vu_meter(sensorValue);
      }
  
    }

   
  return 0;
}
