Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum States {
- STARTUP,
- WAITING,
- MEASURING,
- SHUTDOWN
- };
- enum States currentState;
- unsigned int timerCounter;
- void setup() {
- currentState = STARTUP;
- }
- void loop() {
- switch (currentState) {
- case STARTUP:
- init();
- break;
- case WAITING:
- //do nothing
- break;
- case MEASURING:
- measure();
- break;
- case SHUTDOWN:
- //shutdown();
- break;
- default:
- currentState = WAITING;
- break;
- }
- }
- void init() {
- TCCR0B |= (1 << CS02) | (1 << CS00);//prescaler set to Fosc/1024 (see page 142)
- TIMSK0 |= (1 << TOV0);//enable Timer0 Overflow Interrupt (see page 143)
- currentState = WAITING;//<--Change the state!
- sei();//enable interrupts
- }
- void measure()
- {
- /* All your measurement and averaging stuff happens here */
- currentState = WAITING;//<--Change the state!
- }
- ISR(TIMER0_OVF_vect)
- {
- timerCounter++;
- if (timerCounter >= 54931)
- {
- timerCounter = 0;
- currentState = MEASURING;//<--Change the state!
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment