#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

/*
  Analog Input
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13. 
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead(). 
 
 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground
 
 * Note: because most Arduinos have a built-in LED attached 
 to pin 13 on the board, the LED is optional.
 
 
 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe
 
 This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/AnalogInput
 
 */

int sensorPinA0 = A0;    // Blue = PB3 = A0
int sensorPinA1 = A1;    // Green = PB4 = A1
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
float mathy = 0;

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  pinMode(2, OUTPUT);  //low
  digitalWrite(2, LOW);
  pinMode(3, OUTPUT);  //pwm
  
  Serial.begin(9600); 
}

void loop() {
 
  // read the value from the sensor:
  sensorValue = analogRead(sensorPinA0); 
  mathy = analogRead(sensorPinA0)*analogRead(sensorPinA1);  
  mathy = map(mathy, -32000, 40000,  0, 255); 
  analogWrite(3,230-mathy);
  // turn the ledPin on
//  digitalWrite(ledPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
//  delay(sensorValue/2);          
  // turn the ledPin off:        
//  digitalWrite(ledPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
//  delay(sensorValue);

//Serial.println(sensorValue);   
Serial.println(mathy);  
}
