...

Arduino Code Snippets


Datatypes:

typebytesrangeGCC type
char 1-128 to 127signed char
byte 10 to 255unsigned char
int 2-32768 to 32767signed short
unsigned int 20 to 65535unsigned short
long 4-2147483648 to 2147483647signed int
unsigned long40 to 4294967295unsigned int
float 4-3.4028235E+38 to 3.4028235E+38float
double 4(reduced to float)float

Blink:

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

Simple serial communication:

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    byte inByte = Serial.read();
    Serial.println("recvd ");
  }
}