Changed microcontroller

main
HollowPurity 2023-07-19 16:18:56 +02:00
parent b4f1487d15
commit a51cd9a97b
1 changed files with 57 additions and 44 deletions

101
servo.ino
View File

@ -1,13 +1,10 @@
/* Sweep /* Sweep
by BARRAGAN <http://barraganstudio.com> by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain. This example code is in the public domain.
modified 28 May 2015 modified 8 Nov 2013
by Michael C. Miller by Scott Fitzgerald
modified 8 Nov 2013 https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
by Scott Fitzgerald
http://arduino.cc/en/Tutorial/Sweep
*/ */
#include <Servo.h> #include <Servo.h>
@ -16,48 +13,64 @@ Servo linkeAugenbraue;
Servo rechteAugenbraue; // create servo object to control a servo Servo rechteAugenbraue; // create servo object to control a servo
// twelve servo objects can be created on most boards // twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int LINKES_AUGE_DEFAULT = 50;
int RECHTES_AUGE_DEFAULT = 40;
void setup() { void setup() {
rechteAugenbraue.attach(D1);
linkeAugenbraue.attach(D4); // attaches the servo on GIO2 to the servo object
pinMode(D2, INPUT_PULLUP);
pinMode(D3, INPUT_PULLUP);
Serial.begin(9600); Serial.begin(9600);
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();
}
void start(){
int origin = linkeAugenbraue.read();
Serial.println(linkeAugenbraue.read());
if(origin > LINKES_AUGE_DEFAULT){
for(int i = origin; i>= LINKES_AUGE_DEFAULT; i--){
linkeAugenbraue.write(i);
delay(15);
}
}
if(origin < LINKES_AUGE_DEFAULT){
for(int i = origin; i<= LINKES_AUGE_DEFAULT; i++){
linkeAugenbraue.write(i);
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);
}
}
} }
void loop() { void loop() {
if (istTasterGedrueckt(D2)) { angry();
for(int i = 0; i<= 90; i++){ delay(2000);
rechteAugenbraue.write(i); start();
linkeAugenbraue.write(i); delay(2000);
} }
void angry(){
Serial.println("Vorwärts"); for(int i = LINKES_AUGE_DEFAULT; i >= 0; i--){
debug(); linkeAugenbraue.write(i);
} rechteAugenbraue.write(80-i);
if (istTasterGedrueckt(D3)) { delay(15);
for(int i = 90; i>= 0; i--){
rechteAugenbraue.write(i);
linkeAugenbraue.write(i);
}
Serial.println("Rückwärts");
debug();
} }
//debug();
}
void debug(){
Serial.write("Spannung auf linker Augenbraue: ");
Serial.println(D4);
Serial.write("Spannung auf rechter Augenbraue: ");
Serial.println(D1);
delay(200);
}
bool istTasterGedrueckt(int taster) {
return digitalRead(taster) == LOW;
} }
bool tasterGedrueckt(int taste) {
return digitalRead(taste) == LOW;
}