#include <XNode.h>
#include <TimedAction.h>
#include <Servo.h>
const int servoPin = 0;
bool increment = true;
short pos = 0;
const int ledPin = 12;
int ledState = LOW;
int randomAngle = random(90);
int LEDrandom = random(100);
bool virus = false;
int i = 0;
int output_pin = 14;
int output_virus_pin = 2;
int input_pin = 4;
int input_virus_pin = 5;
XNode node(input_pin, output_pin, input_virus_pin, output_virus_pin);
Servo myservo;
void ledBlink() {
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
TimedAction ledThread = TimedAction(500, ledBlink);
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
node.init();
node.setInterval(50);
}
void loop() {
if ( virus == true) {
myservo.attach(0);
myservo.write(randomAngle);
delay(30);
randomAngle = random(90);
LEDrandom = random(100);
if (LEDrandom < 50) {
digitalWrite(ledPin, LOW);
}
else {
digitalWrite(ledPin, HIGH);
}
}
else {
ledThread.check();
myservo.attach(0);
for (pos = 0; pos <= 90; pos++) {
ledThread.check();
myservo.write(pos);
Serial.println(pos);
delay(15);
if (pos == 90) {
node.send();
Serial.println("senden");
}
}
myservo.detach();
digitalWrite(0, LOW);
for (i = 0; i <= 5000; i++) {
ledThread.check();
delay(1);
}
myservo.attach(0);
for (pos = 90; pos >= 0; pos--) {
ledThread.check();
myservo.write(pos);
Serial.println(pos);
delay(15);
}
myservo.detach();
digitalWrite(0, LOW);
for (i = 0; i <= 5000; i++) {
ledThread.check();
delay(1);
}
}
}