-
Notifications
You must be signed in to change notification settings - Fork 0
Arduino cheat sheet
Benedict Allen edited this page Oct 7, 2019
·
3 revisions
You need a setup and loop function defined, each taking no parameters and returning void.
void setup() {
// do stuff
}
void loop() {
// do stuff
}setup is called once at the beginning then loop is called repeatedly after that.
digitalWrite(pin, value); // value is HIGH or LOW
analogWrite(pin, value); // value is 0-255 inclusiveDon't forget to use
pinMode(pin, OUTPUT);first.
value = digitalRead(pin);
value = analogRead(pin);
Don't forget to use
pinMode(pin, INPUT);first.
To write things using serial, use print or println.
Serial.println("stuff");
Serial.print("stuff without a newline at the end");To read things, use available to get the number of bytes available, and read to read a byte.
if (Serial.available()) {
int byte = Serial.read();
}To pause for some time, use delay.
delay(time); // time is in milliseconds