Changed microcontroller
parent
b4f1487d15
commit
a51cd9a97b
89
servo.ino
89
servo.ino
|
@ -2,12 +2,9 @@
|
|||
by BARRAGAN <http://barraganstudio.com>
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 28 May 2015
|
||||
by Michael C. Miller
|
||||
modified 8 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
|
||||
http://arduino.cc/en/Tutorial/Sweep
|
||||
https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
|
||||
*/
|
||||
|
||||
#include <Servo.h>
|
||||
|
@ -16,48 +13,64 @@ Servo linkeAugenbraue;
|
|||
Servo rechteAugenbraue; // create servo object to control a servo
|
||||
// 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() {
|
||||
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);
|
||||
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() {
|
||||
if (istTasterGedrueckt(D2)) {
|
||||
for(int i = 0; i<= 90; i++){
|
||||
rechteAugenbraue.write(i);
|
||||
angry();
|
||||
delay(2000);
|
||||
start();
|
||||
delay(2000);
|
||||
}
|
||||
void angry(){
|
||||
for(int i = LINKES_AUGE_DEFAULT; i >= 0; 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue