Escolar Documentos
Profissional Documentos
Cultura Documentos
Caractersticas Fsicas
Caractersticas Fsicas
Caractersticas Fsicas
Caractersticas Fsicas
Estrutura de um programa
pinMode(<porta>, <modo>): configura uma porta digital para ser lida ou para enviarmos dados;
digitalWrite(<porta>, 0 ou 1): envia 0 ou 1 para porta digital digitalRead(<porta>): retorna um 0 ou 1 lido da porta analogRead(<porta>): retorna de 0 a 1023 com o valor da porta analgica analogWrite(<porta>, <valor>): escreve em uma porta PWM um valor de 0 a 255
// turns the LED on // waits for a second // turns the LED off // waits for a second
void setup() { pinMode(LED, OUTPUT); // tell Arduno LED is an output pinMode(BUTTON, INPUT); // and BUTTON is an input } void loop(){ val = digitalRead(BUTTON); // read input value and store it // check whether the input is HIGH (button pressed) if (val == HIGH) { digitalWrite(LED, HIGH); } else { digitalWrite(LED, LOW); } } // turn LED ON
}
void loop() { val = analogRead(0); analogWrite(LED, val/4); delay(10); } // read the value from the sensor // turn the LED on at the brightness set by the sensor // stop the program for some time
Nota: especificar o brilho que dividindo por 4 val, porque analogRead () retorna um nmero at 1023, e analogWrite () aceita um mximo de 255.