ArduinoCheatsheet

LED aan

  pinMode(led, OUTPUT);      // SET MODE
  digitalWrite(led, HIGH);   // AAN
  digitalWrite(led, LOW);    // UIT

Wacht een seconde

  delay(1000);               // SECONDE

Lees invoer

  const int sensor = A0;
  float sensorValue = analogRead(sensor);

Lees button

  pinMode(2,INPUT);           // SET MODE
  if (digitalRead(button) == HIGH) { }

Button

actionNeeded = true;
buttonState = digitalRead(button);

if (buttonState1 == HIGH) {

  if (actionNeeded) {
    // Do... 
    actionNeeded = false;      // No more action in this push
  }
} else {
  actionNeeded = true;         // Prepare for next push
}

Buzzer

const int buzzer = 2;
pinMode(buzzer,OUTPUT);
tone(buzzer,i);               // Output frequency
delay(5);                     // For 5ms 

Seriele monitor

  Serial.begin(9600);
  Serial.print("Hallo wereld");
  Serial.println("Losse regel");

Servo

#include              // Load included servo library
const int servo = 9;           // Set pin
Servo myservo;                 // Create servo object
myservo.attach(servo);         // Connect object to pin
myservo.write(pos);            // Rotate servo

RGB LED

#define COMMON_ANODE     // Definition for ANODE, remove line for KATHODE
const int pinRed = 2;
const int pinGreen = 3;
const int pinBlue = 4;
pinMode(pinRed, OUTPUT);
pinMode(pinGreen, OUTPUT);
pinMode(pinBlue, OUTPUT);  
showLed(255,0,0); //  red

void showLed(int red, int green, int blue) {

  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  
  analogWrite(pinRed, red);
  analogWrite(pinGreen, green);
  analogWrite(pinBlue, blue);
}

Definities

const int ledRed = 2;         // Constate
int ledGreen = 3;             // Variabel

FOR loop

for(int i = 2; i < 5; i++) {