//Abhiyaan Elec Module App EE22B047
//Absolute encoder simulator
//Setting initial position to 0
int position = 0;
void setup()
{
//Enabling pins 2 to 12 to simulate encoder inputs
for (int i = 2; i < 12; i++)
{
pinMode(i, INPUT_PULLUP);
}
//Starting the serial monitor for display
Serial.begin(115200);
}
void loop()
{
//Iterating through each bit
for (int i = 11; i > 1; i--)
{
//Adding 2 raised to the power of the bit if bit results in 1
if (digitalRead(i)==0)
{
int a = lround(pow(2, i-2));
position += a;
}
}
//Printing position
Serial.println(position);
//Setting position to 0 for next iteration
position = 0;
//Giving a break of 1s between every check
delay(1000);
}