#define DATA_PIN 8
#define LATCH_PIN 9
#define CLOCK_PIN 10
int8_t output = 0;
uint16_t speedDelay = 20;
int8_t val[4] = {10, 6, 5, 9};//1010 0110 0101 1001
uint16_t count = 0;
void cwSeq() {
for (int8_t i = 0; i < 4; i ++) {
count ++;
output = val[i];
updateShiftRegister();
if (count < 5) goPrint();
delay(speedDelay);
}
}
void ccwSeq() {
for (int8_t i = 3; i >= 0; i --) {
count --;
output = val[i];
updateShiftRegister();
if (count > 195) goPrint();
delay(speedDelay);
}
}
void updateShiftRegister() {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, output);
digitalWrite(LATCH_PIN, HIGH);
}
void goPrint() {
Serial.print(output);
if (output > 9) Serial.print(" ");
else Serial.print(" ");
for (int8_t bit = 3; bit >= 0; bit--) {
Serial.print(bitRead(output, bit));
}
Serial.println();
}
void setup() {
Serial.begin(115200);
Serial.println("Hello");
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
for (int16_t i = 0; i < 50; i ++) {//50 loops x 4 steps = 200
cwSeq();
}
Serial.println(count);
delay(1000);
for (int16_t i = 0; i < 50; i ++) {
ccwSeq();
}
Serial.println(count);
delay(1000);
}