//sensercode for any 5v arduino long oldmillis = 0; long w = 0; int y = 0; int a = 0; int b = 0; int bb = 0; int c = 0; int cc = 0; int e = 0; int f = 0; int g = 0; int h = 0; int j = 10; //make this smaller to speed up or bigger to slow down int pot; boolean state1a = true; boolean state2a = true; boolean state1b = true; boolean state2b = true; boolean state1c = true; boolean state2c = true; byte bits; void setup() { pinMode(10,OUTPUT); digitalWrite(10, LOW); pinMode(8,OUTPUT); pinMode(9,OUTPUT); Serial.begin(9600); } void loop() { w = millis() - oldmillis; if(y == 2 && w > j*3) { if(f == 1 && cc == c) { f = 2; // # disable this for accuracy before update at start } if(f == 1 ) { bits = serial(c); } if(f == 2 && bb == b) { f = 3;// # disable this for accuracy before update at start } if(f == 2 ) { bits = serial(b); } if(f == 3 ) { bits = serial(a); f = 0; cc = c; bb = b; g++;//counter increment, disable this when using analog input // pot = analogRead(A0);// enable this when using a potentiometer or a sensor // g = map(pot,0,1023,0,999);// idem e = g/10; h = g/100; a = g - (e*10); // a is for the units b = e - (h*10) + 10;//b is for the tens c = h + 20; // c = for the hunderds if( g > 999) { g = 0; } } digitalWrite(10,LOW); digitalWrite(9,state1a); digitalWrite(8,state2a); f++; y = 0; w = 0; oldmillis = millis(); } if(y == 0 && w > j) { digitalWrite(10,HIGH); digitalWrite(9,state1b); digitalWrite(8,state2b); y = 1; } if(y == 1 && w > j*2) { digitalWrite(9,state1c); digitalWrite(8,state2c); y = 2; } } byte serial(int getalnr) { switch (getalnr) { case 0://////////// units state1a = 0; state2a = 0;//0 state1b = 0; state2b = 0;//0 state1c = 0; state2c = 1;//2 break; case 1:// state1a = 1; state2a = 0;//1 state1b = 0; state2b = 0;//0 state1c = 0; state2c = 1;//2 break; case 2: state1a = 0; state2a = 0;//0 state1b = 1; state2b = 0;//1 state1c = 0; state2c = 1;//2 break; case 3: state1a = 1; state2a = 0;//1 state1b = 1; state2b = 0;//1 state1c = 0; state2c = 1;//2 break; case 4: state1a = 0; state2a = 0;//0 state1b = 0; state2b = 1;//2 state1c = 0; state2c = 0;//0 break; case 5: state1a = 1; state2a = 0;//1 state1b = 0; state2b = 1;//2 state1c = 0; state2c = 0;//0 break; case 6: state1a = 0; state2a = 1;//2 state1b = 0; state2b = 1;//2 state1c = 0; state2c = 0;//0 break; case 7: state1a = 1; state2a = 0;//1 state1b = 1; state2b = 1;//3 state1c = 0; state2c = 0;//0 break; case 8: state1a = 0; state2a = 1;//2 state1b = 1; state2b = 1;//3 state1c = 0; state2c = 0;//0 break; case 9: state1a = 1; state2a = 1;//3 state1b = 1; state2b = 1;//3 state1c = 0; state2c = 0;//0 break; case 10:////////////tens state1a = 0; state2a = 0;//0 state1b = 0; state2b = 0;//0 state1c = 1; state2c = 1;//3 break; case 11:// state1a = 1; state2a = 0;//1 state1b = 0; state2b = 0;//0 state1c = 1; state2c = 1;//3 break; case 12: state1a = 0; state2a = 0;//0 state1b = 1; state2b = 0;//1 state1c = 1; state2c = 1;//3 break; case 13: state1a = 1; state2a = 0;//1 state1b = 1; state2b = 0;//1 state1c = 1; state2c = 1;//3 break; case 14: state1a = 0; // state2a = 0;//0 state1b = 0; state2b = 1;//2 state1c = 1; state2c = 0;//1 break; case 15: state1a = 1; state2a = 0;//1 state1b = 0; state2b = 1;//2 state1c = 1; state2c = 0;//1 break; case 16: state1a = 0; state2a = 1;//2 state1b = 0; state2b = 1;//2 state1c = 1; state2c = 0;//1 break; case 17: state1a = 1; state2a = 0;//1 state1b = 1; state2b = 1;//3 state1c = 1; state2c = 0;//1 break; case 18: state1a = 0; state2a = 1;//2 state1b = 1; state2b = 1;//3 state1c = 1; state2c = 0;//1 break; case 19: state1a = 1; state2a = 1;//3 state1b = 1; state2b = 1;//3 state1c = 1; state2c = 0;//1 break; case 20://////// hunderds state1a = 0; state2a = 0;//0 state1b = 0; state2b = 0;//0 state1c = 1; state2c = 0;//1 break; case 21:// state1a = 21; state2a = 0;//1 state1b = 0; state2b = 0;//0 state1c = 1; state2c = 0;//1 break; case 22: state1a = 0; state2a = 0;//0 state1b = 1; state2b = 0;//1 state1c = 0; state2c = 0;//0 break; case 23: state1a = 1; state2a = 0;//1 state1b = 1; state2b = 0;//1 state1c = 0; state2c = 0;//0 break; case 24: state1a = 0; state2a = 0;//0 state1b = 0; state2b = 1;//2 state1c = 1; state2c = 1;//3 break; case 25: state1a = 1; state2a = 0;//1 state1b = 0; state2b = 1;//2 state1c = 1; state2c = 1;//3 break; case 26: state1a = 0; state2a = 1;//2 state1b = 0; state2b = 1;//2 state1c = 1; state2c = 1;//3 break; case 27: state1a = 1; state2a = 0;//1 state1b = 1; state2b = 1;//3 state1c = 0; state2c = 1;//2 break; case 28: state1a = 0; state2a = 1;//2 state1b = 1; state2b = 1;//3 state1c = 0; state2c = 1;//2 break; case 29: state1a = 1; state2a = 1;//3 state1b = 1; state2b = 1;//3 state1c = 0; state2c = 1;//2 break; } }