So I'm having a bit of issue when compiling this code that I'm adding to for an ultrasonic sensor with a bluetooth slave model. sensor is an sr04 and the module is an hc06
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400
#define senValue1
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
const int sensor1 = A0;
void setup() {
pinMode(sensor1, INPUT);
Serial.begin(115200);
}
void loop() {
int senValue = analogRead(sensor1);
senValue1 = map(senValue1, 0, 400, 0, 400);
Serial.print(" ");
Serial.print(senValue1);
delay(50);
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
}
Every time I attempt to compile I'm getting an "expected primary expression before '=' token on the line " senValue1 = map(senValue1, 0, 400, 0, 400);". Any assistance would be appreciated.
KeithRB:
Do you want senValue or seValue1? You #define senValue1 as a blank
I'm looking to find senValue1
PaulS:
#define senValue1
This defines a name with no value. It does NOT define a variable.
senValue1 = map(senValue1, 0, 400, 0, 400);
When the preprocessor is done, this line looks like:
= map(, 0, 400, 0, 400);
See why the compiler is complaining?
what would be a recommendation for a solution? should I just drop the senValue1 in map(senValue1, 0, 400, 0, 400) or just write a new line to assign the value that the sensor is giving? the main goal is to take the values that the sensor is giving, and then send them wirelessly over to my android device to display
PaulS:
I don't know what you are trying to map, or what you are trying to use the mapped value for.
It doesn't seem useful to call map with the same to range as the from range.
So, step back from the "How do I...", and explain what it is you are trying to do.
The main goal of what I'm trying to do is have the sr04 sensor take distance readings, and transmit these readings to an android device via the hc06 slave model
He's not being a dick. He's honestly confused about what you mean to do there. How would you take an analog reading to get a serial signal. If you don't understand the confusion then perhaps you should do a little research on the difference between analog and digital signals. Once you understand that difference you'll probably think wtf was I thinking too.