Hi there,
I am trying to write my first code after copy pasting for a couple of days. I am having trouble finding the errors I have left behind in this script and was wondering if you guys could help me out a bit.
much appreciated.
this is the error:
error: expected unqualified-id before '{' token
Here is the code:
unsigned long time;
const int PIR_0 = 1;
const int PIR_1 = 2;
const int PIR_2 = 3;
const int uSonic = 6;
const int PWMPin = 4;
const int constantPower = 5;
//Random modus when people are not in a certain radius
int timer = random(40, 800);
int uValue = 400;
int pwmTimer = random(0, 100);
int pwmtimer2 = random (200, 255);
void Setup() {
Serial.begin(9600);
pinMode(PIR_0, INPUT);
pinMode(PIR_1, INPUT);
pinMode(PIR_2, INPUT);
pinMode(PWMPin, OUTPUT); //DCmotor pin for PWM the direction. PWM 126 = no movement, PWM 255 = backward PWM 0= forward
pinMode(constantPower, OUTPUT); //DCmotor pin for activating the IC (LMD18200)
digitalWrite (constantPower, HIGH);
}
void Loop() {
long duration, cm;
//calibration of the Ultrasonic sensor
pinMode(uSonic, OUTPUT);
digitalWrite(uSonic, LOW);
delayMicroseconds(2);
digitalWrite(uSonic, HIGH);
delayMicroseconds(5);
digitalWrite(uSonic, LOW);
//the same pin is used to read the signal
pinMode(uSonic,INPUT);
duration = pulseIn(uSonic, HIGH);
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay (200);
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
//------------------------------------------------------------
int zahl = random(2);
{
if(PIR_0 == HIGH || zahl == 0) {
analogWrite(PWMPin, 127);
}
else if(uSonic <= uValue) {
analogWrite(PWMPin, 255);
}
else if(PIR_0 == HIGH || zahl ==1) {
analogWrite(PWMPin, 0);
}
else if(uSonic =< uValue) {
analogWrite(PWMPin, 255);
}
}
{
if (PIR_1 == HIGH) {
analogWrite(PWMPin, 0);
}
else if (uSonic <= uValue) {
analogWrite(PWMPin, 127);
}
}
{
if PIR_2 == HIGH {
analogWrite(PWMPin, 255);
}
else if (uSonic <= uValue) {
analogWrite(PWMPin, 127);
}
}
int moving = random(2);
{
if (moving = 0 || uSonic <= uValue) {
analogWrite(pwmTimer);
}
delay(timer);
analogWrite(PWMPin, 127);
if else (moving= 1 || uSonic <= uValue) {
analogWrite(pwmTimer2);
}
delay(timer);
analogWrite(PWMPin, 127);
}
best regards,
Tom