#include <SimpleRotary.h>
const int NUM_ENCODERS = 5;
const int EN_CLK_PINS[] = {11, 8, 5, 2, A0};
const int EN_DT_PINS[] = {12, 9, 6, 3, A1};
const int EN_SW_PINS[] = {13, 10, 7, 4, A2};
const char ENC_NAME[NUM_ENCODERS][5] = {
{"enc1"}, {"enc2"}, {"enc3"}, {"enc4"}, {"enc5"}
};
char nameBuff[8];
//char *encNames[NUM_ENCODERS];
//Servo servoArray[SERVO_NUM]; // create aaray of servo object
void initEncoders() {
//char nameBuff[8];
for (int i = 0; i < NUM_ENCODERS; i++) {
Serial.println(ENC_NAME[i]);
snprintf(nameBuff, 8, "%s", ENC_NAME[i]);
//char enc_name[8] = {ENC_NAME[i]};
Serial.println(nameBuff);
SimpleRotary nameBuff(EN_CLK_PINS[i], EN_DT_PINS[i], EN_SW_PINS[i]);
}
}
/*
char enc_name = ENC_NAME[0];
SimpleRotary enc_name(EN_CLK_PINS[0], EN_DT_PINS[0], EN_SW_PINS[0]);
SimpleRotary encoder[1](EN_CLK_PINS[1], EN_DT_PINS[1], EN_SW_PINS[1]);
SimpleRotary encoder[2](EN_CLK_PINS[2], EN_DT_PINS[2], EN_SW_PINS[2]);
SimpleRotary encoder[3](EN_CLK_PINS[3], EN_DT_PINS[3], EN_SW_PINS[3]);
SimpleRotary encoder[4](EN_CLK_PINS[4], EN_DT_PINS[4], EN_SW_PINS[4]);
*/
///*
SimpleRotary rotary1(EN_CLK_PINS[0], EN_DT_PINS[0], EN_SW_PINS[0]);
SimpleRotary rotary2(EN_CLK_PINS[1], EN_DT_PINS[1], EN_SW_PINS[1]);
SimpleRotary rotary3(EN_CLK_PINS[2], EN_DT_PINS[2], EN_SW_PINS[2]);
SimpleRotary rotary4(EN_CLK_PINS[3], EN_DT_PINS[3], EN_SW_PINS[3]);
SimpleRotary rotary5(EN_CLK_PINS[4], EN_DT_PINS[4], EN_SW_PINS[4]);
//*/
//SimpleRotary ENC_NAME[0](EN_CLK_PINS[0], EN_DT_PINS[0], EN_SW_PINS[0]);
//SimpleRotary ENC_NAME[0] = new SimpleRotary(EN_CLK_PINS[i], EN_DT_PINS[i], EN_SW_PINS[i]);
//void createEncoder(int num) {
//SimpleRotary ENC_NAME[0](EN_CLK_PINS[0], EN_DT_PINS[0], EN_SW_PINS[0]);
//}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
//initEncoders();
//Serial.println(ENC_NAME[0]);
//SimpleRotary encName[0] = new SimpleRotary(EN_CLK_PINS[0], EN_DT_PINS[0], EN_SW_PINS[0]);
//for (int i = 0; i < NUM_ENCODERS; i++) {
//encNames[i] = ENC_NAME[i];
//encoder[i](EN_CLK_PINS[i], EN_DT_PINS[i], EN_SW_PINS[i]);
//SimpleRotary encNames[i] = new SimpleRotary(EN_CLK_PINS[0], EN_DT_PINS[0], EN_SW_PINS[0]);
//createEncoder(ENC_NAME[0]);
//encoder[i].setDebounceDelay(5);
//encoder[i].setErrorDelay(250);
//encoder[i].setTrigger(HIGH);
//}
Serial.println("Ready");
//int value = ENC_NAME[0]->rotate();
//Serial.println(value);
}
void loop() {
///*
// put your main code here, to run repeatedly:
//delay(10); // this speeds up the simulation
// 0 = not turning, 1 = CW, 2 = CCW
int i1 = rotary1.rotate();
if ( i1 == 1 ) {
Serial.println("CW 1");
}
if ( i1 == 2 ) {
Serial.println("CCW 1");
}
///*
int i2 = rotary2.rotate();
if ( i2 == 1 ) {
Serial.println("CW 2");
}
if ( i2 == 2 ) {
Serial.println("CCW 2");
}
int i3 = rotary3.rotate();
if ( i3 == 1 ) {
Serial.println("CW 3");
}
if ( i3 == 2 ) {
Serial.println("CCW 3");
}
int i4 = rotary4.rotate();
if ( i4 == 1 ) {
Serial.println("CW 4");
}
if ( i4 == 2 ) {
Serial.println("CCW 4");
}
int i5 = rotary5.rotate();
if ( i5 == 1 ) {
Serial.println("CW 5");
}
if ( i5 == 2 ) {
Serial.println("CCW 5");
}
//*/
}