Skip to content

Instantly share code, notes, and snippets.

@giljr
Created December 2, 2018 02:00
Show Gist options
  • Save giljr/9aca4e02171731fdde209f7c0e0a50bf to your computer and use it in GitHub Desktop.
Save giljr/9aca4e02171731fdde209f7c0e0a50bf to your computer and use it in GitHub Desktop.
/*
Kids-Serie#10
Project : Arduino Start Up
Ino File: _10_All_Features_05.ino
*/
#include <Servo.h>
Servo myServo;
void setup() { // put your setup code here, to run once:
// Code 1 - LED
pinMode(3, OUTPUT);
// Code 2
pinMode(7, INPUT); // Pot connected
// Code 4 - Servo
myServo.attach(9);
}
void loop() { // put your main code here, to run repeatedly:
// Code 2
if (digitalRead(7) == HIGH) { // is button pressed?
digitalWrite(3, HIGH); // yes, then light LED
} else {
digitalWrite(3, LOW); // no, turn off the led ;)
}
// Code 4 - Servo
int potValue = analogRead(0); // readings from the potentiometer and transform
potValue = map(potValue, 0, 1023, 0, 180);
myServo.write(potValue); // the number so the servo turns 180º
delay(15);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment