Hi, I'm a high school student who's working on a project with Ultrasound, the purpose of the project is to make the buzzer sound when the Ultrasound emitter detects an object, also a green LED will flash when there's no obstruction and a red one when there's an obstacle, I get the problem mentioned above like 3 times in the error message, I'll show it to you now (SOME EXPLANATIONS ARE IN SPANISH, LIKE PIN VERDE WITH STANDS FOR GREEN PIN):
#include <Ultrasonic.h>
/Opiron Electronics by A.Girod
Programación de un sensor de aparcamiento con alarma visual y acústica
Mediante la libreria Ultrasonic
by Anton Girod (girodanton@gmail.com)
bajo licencia Creative Commons Attribution-ShareAlike 3.0/
#include "Ultrasonic.h"
Ultrasonic ultrasonic(12,13); // En lugar de declarar los Pin echo y Pin trig, puedo hacerlo directamente con esta función
int Pinrojo=6;
int Pinverde=5;
int buzzer=4;
void setup() {
Serial.begin (9600);
pinMode(Pinverde,OUTPUT); //Definimos los pines, notar que ya no definimos los pines del sensor
pinMode(Pinrojo, OUTPUT);
pinMode(buzzer,OUTPUT);
}
void loop() {
int cm;
Serial.print("Duración del pulso de recepción:");
Serial.print(Ultrasonic.Timing(" us")); //Aqui obtenemos el tiempo del pulso de eco en high
Serial.println(" us");
cm=Ultrasonic.Ranging(cm); //Aqui hacemos la conversión a cm
Serial.print("Distancia: ");
Serial.print(Ultrasonic.Ranging(" cm"));
Serial.println(" cm");
if (cm>20) //20 cm es la distancia de emergencia
{
digitalWrite(Pinverde, HIGH); //En caso que un objeto esté lejos, pintamos el LED verde
digitalWrite(Pinrojo, LOW);
digitalWrite(buzzer, LOW);
}
else if (cm<20)
{
digitalWrite(Pinverde, LOW); //Si el objeto está muy cerca, hacemos sonar la alarma buzzer y el LED rojo
digitalWrite(Pinrojo, HIGH);
digitalWrite(buzzer, HIGH);
}
delay(500);
}
AND NOW THE ERROR MESSAGES:
Arduino: 1.5.5-r2 (Windows 8), Placa:"Arduino Uno"
BASTON_ARDUINO.ino: In function 'void loop()':
BASTON_ARDUINO:30: error: expected primary-expression before '.' token
BASTON_ARDUINO:32: error: expected primary-expression before '.' token
BASTON_ARDUINO:34: error: expected primary-expression before '.' token
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.