Folha de dicas do Arduino #1
Em um artigo anterior, já discutimos sobre o Arduino - a popular plataforma de hardware e firmware de código aberto usada para construir eletrônicos DIY. Neste artigo vamos passar por uma folha de dicas que criei enquanto ainda estava aprendendo Arduino, mas admito que continuo a usá-lo!
Aqui está uma folha de dicas detalhada do Arduino que cobre algumas das funções mais usadas do Arduino:
delay(ms):
Esta função pausa o programa por um número especificado de milissegundos. A função de atraso é muito útil em casos como piscar um LED, onde é necessário que haja uma lacuna entre o estado ligado e desligado do led para que nossos olhos vejam, sem usar o atraso, o LED piscaria muito rapidamente e o efeito de piscar seria difícil ver.
delay(1000); // waits for 1 second or 1000 milliseconds
delayMicroseconds(1000); // waits for 1 delay milliseconds or 1000 microseconds
pinMode(13, OUTPUT); // sets the pin 13 as output mode
pinMode(4, INPUT); // set pin 4 to input mode
pinMode(5, INPUT_PULLUP); // set pin 5 to input pullup mode
digitalWrite(13, HIGH); // sets the pin 13 on
int val = 0; // variable to store the read value
pinMode(4, INPUT); // sets the digital pin 4 as input
val = digitalRead(4); // read pin 4 and store in integer variable val
analogWrite(5, 128); // sets the pin 5 to 50% duty cycle
int val = 0; // variable to store the read value
val = analogRead(A0); // read the analog value of pin A0 and store in integer variable val
Serial.begin(9600); // initialise serial communication at 9600 baudrate
int val = 123;
Serial.print(val); // prints the integer variable val to the serial port
int val = Serial.read(); // reads a value from the serial port and stores it in the integer variable val
String myString = ""; // initialise empty string
String myString = Serial.readString(); //read until timeout
Photo by Daniel Andrade on Unsplash