arduino_summerschool/servo.ino

76 lines
1.7 KiB
Arduino
Raw Permalink Normal View History

2023-07-19 14:22:32 +02:00
/* Sweep
2023-07-19 16:18:56 +02:00
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
2023-07-19 14:22:32 +02:00
2023-07-19 16:18:56 +02:00
modified 8 Nov 2013
by Scott Fitzgerald
https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
2023-07-19 14:22:32 +02:00
*/
#include <Servo.h>
Servo linkeAugenbraue;
Servo rechteAugenbraue; // create servo object to control a servo
// twelve servo objects can be created on most boards
2023-07-19 16:18:56 +02:00
int pos = 0; // variable to store the servo position
int LINKES_AUGE_DEFAULT = 50;
int RECHTES_AUGE_DEFAULT = 40;
2023-07-19 14:22:32 +02:00
void setup() {
Serial.begin(9600);
2023-07-19 16:18:56 +02:00
linkeAugenbraue.attach(10); // attaches the servo on pin 9 to the servo object
rechteAugenbraue.attach(9);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
start();
2023-07-19 14:22:32 +02:00
}
2023-07-19 16:18:56 +02:00
void start(){
int origin = linkeAugenbraue.read();
Serial.println(linkeAugenbraue.read());
if(origin > LINKES_AUGE_DEFAULT){
for(int i = origin; i>= LINKES_AUGE_DEFAULT; i--){
2023-07-19 14:43:27 +02:00
linkeAugenbraue.write(i);
2023-07-19 16:18:56 +02:00
delay(15);
2023-07-19 14:43:27 +02:00
}
2023-07-19 14:22:32 +02:00
}
2023-07-19 16:18:56 +02:00
if(origin < LINKES_AUGE_DEFAULT){
for(int i = origin; i<= LINKES_AUGE_DEFAULT; i++){
2023-07-19 14:43:27 +02:00
linkeAugenbraue.write(i);
2023-07-19 16:18:56 +02:00
delay(15);
}
}
origin = rechteAugenbraue.read();
Serial.println(rechteAugenbraue.read());
if(origin > RECHTES_AUGE_DEFAULT){
for(int i = origin; i>= RECHTES_AUGE_DEFAULT; i--){
rechteAugenbraue.write(i);
delay(15);
}
}
if(origin < RECHTES_AUGE_DEFAULT){
for(int i = origin; i<= RECHTES_AUGE_DEFAULT; i++){
rechteAugenbraue.write(i);
delay(15);
2023-07-19 14:43:27 +02:00
}
2023-07-19 14:22:32 +02:00
}
}
2023-07-19 16:18:56 +02:00
void loop() {
angry();
delay(2000);
start();
delay(2000);
2023-07-19 14:22:32 +02:00
}
2023-07-19 16:18:56 +02:00
void angry(){
for(int i = LINKES_AUGE_DEFAULT; i >= 0; i--){
linkeAugenbraue.write(i);
rechteAugenbraue.write(80-i);
delay(15);
}
2023-07-19 14:22:32 +02:00
}
2023-07-19 16:18:56 +02:00
bool tasterGedrueckt(int taste) {
return digitalRead(taste) == LOW;
}