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

View File

@ -2,12 +2,9 @@
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
by Michael C. Miller
modified 8 Nov 2013 modified 8 Nov 2013
by Scott Fitzgerald by Scott Fitzgerald
https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
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();
delay(2000);
}
void angry(){
for(int i = LINKES_AUGE_DEFAULT; i >= 0; i--){
linkeAugenbraue.write(i); linkeAugenbraue.write(i);
rechteAugenbraue.write(80-i);
delay(15);
} }
Serial.println("Vorwärts");
debug();
}
if (istTasterGedrueckt(D3)) {
for(int i = 90; i>= 0; i--){
rechteAugenbraue.write(i);
linkeAugenbraue.write(i);
}
Serial.println("Rückwärts");
debug();
} }
//debug(); bool tasterGedrueckt(int taste) {
return digitalRead(taste) == LOW;
} }
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;
}