Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int DEFAULT_DELAY_SLICE = 10;
- void setup()
- {
- pinMode( 13 , OUTPUT);
- pinMode( 12 , OUTPUT);
- pinMode( 11 , OUTPUT);
- pinMode( 10 , OUTPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- changeStatusWithDelay(turnOn);
- changeStatusWithDelay(turnOff);
- }
- void changeStatusWithDelay(void (*f)(int))
- {
- int totalPortDelay = 0;
- for (int port = 13; port >= 10; port--)
- {
- f( port );
- while(totalPortDelay < getDelayTime())
- {
- delay( DEFAULT_DELAY_SLICE );
- totalPortDelay += DEFAULT_DELAY_SLICE;
- }
- totalPortDelay = 0;
- }
- }
- void turnOn(int port) { digitalWrite( port , HIGH ); }
- void turnOff(int port) { digitalWrite( port , LOW ); }
- int getDelayTime()
- {
- int delayTime = 20;
- int photo_voltage = analogRead(0) ;
- Serial.print("message");
- Serial.print(photo_voltage);
- Serial.println();
- if (photo_voltage > 0)
- delayTime = photo_voltage * 20;
- return delayTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement