C++ programmering

På denne side, vil jeg skrive om mine erfaringer med programmering i sproget C++, og lave en quikguide på dansk.

Skabelon


void setup() {
// comment

}

void loop() {
// comment

}

Blink


// Blink

int ledPin = 13; // pin that the LED is attached to

void setup() {
pinMode(ledPin, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off
delay(1000); // wait for a second
}

Light on/off – If statement


// Light on/off - If statement

int buttonPin = 12; // pin that the button is attached to
int ledPin = 13; // pin that the LED is attached to

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {

if (buttonPin == HIGH) {
digitalWrite(ledPin, HIGH); // turn the LED on
} else {
digitalWrite(ledPin, LOW); // turn the LED off
}
}

Light on/off – Switch statement


// Light on/off - Switch statement

int buttonPin = 12; // pin that the button is attached to
int ledPin = 13; // pin that the LED is attached to

void setup() {
}

void loop() {

int buttonPin = 12; // pin that the button is attached to
int ledPin = 13; // pin that the LED is attached to

switch (buttonPin == HIGH) {
case 0: // Push on the button
digitalWrite(ledPin, HIGH); // turn the LED on
break;
case 1: // No push on the button
digitalWrite(ledPin, LOW); // turn the LED off
break;
}
}


Datatyper
Funktioner
Variabler
Class & object
Make Library
Boolean
Analog Read

While loop
do-while loop
nested loop