Go Down

Topic: Program error "stray '\' in program" (Read 5078 times) previous topic - next topic

XnIcRaM

I try to build ohmmeter,  but have an error in program, what I do wrong?

This is my source code:

Code: [Select]
float r1= 10000.0;

void setup()
{
Serial.begin(9600);
}
void loop()
{
float Uwyj = (5.0/1024.0) * float(analogRead(0));
float R=r1*((5.0/Uwyj) - 1);
Serial.print("Napiecie wyj: "); Serial.println(Uwyj); 
Serial.print("Wartosc rezystora: "); Serial.println(R);
delay(3000);
}



This is error message I get:
Code: [Select]
sketch_mar15a:10: error: stray '\' in program
sketch_mar15a.ino: In function 'void loop()':
sketch_mar15a:10: error: expected `)' before 'u2013'

PaulS

There is something wrong with your - sign here:
Code: [Select]
float R=r1*((5.0/Uwyj) - 1);
Deleting it, and replacing it with a regular minus sign allows the code to compile;.
The art of getting good answers lies in asking good questions.


robtillaart

A few tips:

- proper indenting and adding spaces makes code more readable
- too much parenthesis can obfuscate code - (OK too few will corrupt code)
- use of constants for 'magic' numbers helps readability
- a header to document the code helps
- a startup message too

Code: [Select]

//    FILE: Ohmmeter.ino
//  AUTHOR: XnIcRaM
// VERSION: 0.1.01
// PURPOSE: Ohmmeter
//    DATE: 2014-xx-xx
//
// <short description of HW here>
//

const int measurePin = 0;
float r1= 10000.0;

void setup()
{
  Serial.begin(9600);
  Serial.println("Ohmmeter 0.1");
}

void loop()
{
  // MEASUREMENT
  int raw = analogRead(measurePin);

  // PROCESS
  float Uwyj = 5.0/1024.0 * raw;
  float R = r1 * ( 5.0/Uwyj) - 1;

  // DISPLAY
  Serial.print("Napiecie wyj: "); Serial.println(Uwyj); 
  Serial.print("Wartosc rezystora: "); Serial.println(R);
  delay(3000);
}

Note the 'process' formulas can be merged, reducing rounding errors.

finally if the raw measurement == 0 you have a problem. (divide by zero)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

wachid_elektronik

I found the solving methode about this "Program error "stray '\' in program"

Just replace all minus sign with the minus on the number pad or (if you are using laptop) use the Fn+":" button to type the minus sign.

below is mine as a sample:
const int ledPin =  13;      // the number of the LED pin


int ledState = LOW;             // ledState used to set the LED

long previousMillis = 0;        // will store last time LED was updated

long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {


pinMode(ledPin, OUTPUT);

}

void loop() {

unsigned long currentMillis = millis();

if (currentMillis- previousMillis>interval){ // ERROR when copy-paste from web, but well done when i replace the minus sign by number pad

previousMillis = currentMillis;

if (ledState == LOW){

ledState = HIGH;

}else{

ledState = LOW;

}


digitalWrite(ledPin, ledState);

}

}


AWOL

I just copied the code from your post into an IDE window, hit "verify", and got this error message
Code: [Select]
Binary sketch size: 1,028 bytes (of a 30,720 byte maximum)
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up