Hey guys,
I am a complete beginner and I am taking a module in university where i need to work with Arduino. I have connected my Uno board with 1Sheeld and ultrasonic sensor. I am using the One sheeld app on my phone and what i am trying to do is reduce or increase the volume of the song my simply going closer/further to the ultrasonic sensor.
I have the code but after trying to upload it a couple of times i keep on getting the same error: Low memory available, stability problems may occur.
Here is my code, i appreciate your help a lot:
#include <OneSheeld.h>
const int trigPin = 2;
const int echoPin = 4;
long distance_cm, cm, duration;
void setup () {
OneSheeld.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
if (ToggleButton.getStatus())
MusicPlayer.play();
else
MusicPlayer.pause();
distance_cm = ultrasonic();
MusicPlayer.setVolume( map( distance_cm, 2, 30, 0, 10));
}
long ultrasonic()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
cm = duration / 29 / 2;
return cm;
}