You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.1 KiB

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)
int atomPins[] = {2,3,4,5,6,7,8,9};
int currentValue = 0;
int values[] = {0,0,0,0,0,0,0,0,0};
int cycle = 0;
void setup() {
Serial.begin(9600);
for(int i=0; i<8; i++) {
pinMode(atomPins[i], OUTPUT);
}
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
delay(10);
}
void loop() {
if(Serial.available()){
int incomingValue = Serial.read();
values[currentValue] = incomingValue;
currentValue++;
if(currentValue > 8){
currentValue = 0;
}
cycle = 0;
}
while(cycle != 8) {
for(int i=0; i<8; i++) {
if(values[i]>0) {
values[i]--;
digitalWrite(atomPins[i], HIGH);
pwm.setPWM(i, 0, 400);
if(values[i]==0) {
digitalWrite(atomPins[i], LOW);
pwm.setPWM(i, 0, 100);
cycle++;
}
}
}
delay(100);
}
}