arduino nuovo, sensore sharp e led 2

Ciao a tutti, cercando su internet ho trovato questa compilazione per far funzionare un sensore sharp con un led.

// define the pins to be used on the microcontroller
#define sensorPin 0
#define ledPin 13

// define the initial value of the sensor variable
int sensorValue = 0;
// compare the sensorValue to this variable to determine if something is in front of the sensor
int threshold = 200;

void setup() {
// set the led pin to output
pinMode(ledPin, OUTPUT);
// open the serial port
Serial.begin(9600);
}

void loop() {
// read the sensor
sensorValue = analogRead(sensorPin);
// print the sensor value
Serial.println(sensorValue, DEC);
// set the led on or off based on the sensor
if (sensorValue & gt; = threshold) {
analogWrite(ledPin, 255);
} else {
analogWrite(ledPin, 0);
}
}

alla dicitura qui:

if (sensorValue & gt; = threshold) {

da errore dicendo che gt non è dichiarato per questo scopo... che cosa significa? come faccio a correggerlo!?

grazie mille

nicole

se togli & gt;
cambia qualcosa?

Prova così :wink:

// define the pins to be used on the microcontroller
#define sensorPin 0
#define ledPin 13

// define the initial value of the sensor variable
int sensorValue = 0;
// compare the sensorValue to this variable to determine if something is in front of the sensor
int threshold = 200;
int gt;

void setup() {
// set the led pin to output
pinMode(ledPin, OUTPUT);
// open the serial port
Serial.begin(9600);
}

void loop() {
// read the sensor
sensorValue = analogRead(sensorPin);
// print the sensor value
Serial.println(sensorValue, DEC);
// set the led on or off based on the sensor
if (sensorValue & gt; = threshold) {
analogWrite(ledPin, 255);
} else {
analogWrite(ledPin, 0);
}
}

non funziona comunque.. nè aggiungendo int gt, nè togliendo & gt;
ora cmq riesco a farlo funzionare con questo codice:

int led13 = 13;
int led7 = 7;//usa il led 13 come led
int analogValue = 0; // variable to hold the analog value

void setup() {
// open the serial port at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog input on pin 0:
analogValue = analogRead(0);
analogValue = analogValue / 4;

// print it out in many formats:
Serial.println(analogValue); // print as an ASCII-encoded decimal
// Serial.print(analogValue, DEC); // print as an ASCII-encoded decimal

// delay 10 milliseconds before the next reading:
delay(10);

if (analogValue > 50 && analogValue < 80)
{
digitalWrite(led13, HIGH);
}
else
{
digitalWrite(led13, LOW);
}

if (analogValue > 80 && analogValue < 120)
{
digitalWrite(led7, HIGH);
}
else
{
digitalWrite(led7, LOW);
}
}

l'unico problema è che nonostante le condizioni per ogni led questi si accendono cmq insieme... io vorrei riuscire a variare la distanza.. tipo tot cm per un led, tot per un'altro... è possibile? è giusto come ho scritto?!

grazie

Nicole