Exempelkod till Arduinoprojekt
Hoppa till navigering
Hoppa till sök
Här samlar vi några användbara kodexempel för sådant som man typiskt behöver göra i projektet.
Eempelkod spänning ut
Exempelkod för att lägga ut en spänning för att styra motorn
/*
Spänning ut
This example shows how to set a voltage to pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int forward = 9; // the pin that the motor is attached to
int velocity = 4; // how fast the motor is running
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(forward, OUTPUT);
}
// voltagee to the motor
void loop() {
// set the voltage of pin 9:
analogWrite(forward, velocity);
delay(20);
}