Hi,
I wanted to create a code that slows down a motor as the value of the sensor increases to 400 where it comes to a full stop.
Here's what I've done so far:
int m1r=2;
int m1l=3;
int m2f=9;
int m2b=11;
const int sensorMin = 150;
const int threshold = 300;
void setup() {
pinMode(m1r, OUTPUT);
pinMode(m1l, OUTPUT);
pinMode(m2f, OUTPUT);
pinMode(m2b, OUTPUT);
}
void loop() {
int sensorReading = analogRead(0);
int analogValue = analogRead(0);
int range = map(analogValue > threshold, sensorMin<analogValue<threshold,0<analogValue<sensorMin);
switch (range) {
case 0:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(m2f, fadeValue);
delay(30);
break;
case 1:
digitalWrite(m2b,LOW);
digitalWrite(m2f,LOW);
digitalWrite(m1r,HIGH);
digitalWrite(m1l,HIGH);
break;
case 2:
digitalWrite(m2f,LOW);
digitalWrite(m2b,HIGH);
digitalWrite(m1r,HIGH);
digitalWrite(m1l,HIGH);
break;
}
I get an error at this line:
int range = map(analogValue > threshold, sensorMin<analogValue<threshold,0<analogValue<sensorMin);
: error: too few arguments to function 'long int map(long int, long int, long int, long int, long int)'
I guess the problem is that there are not enough conditions?
Thanks