Difference between revisions of "Arduino Programming Fundamentals"

From Interaction Station Wiki
Jump to navigation Jump to search
Line 5: Line 5:
 
= Beyond the delay() =  
 
= Beyond the delay() =  
 
== A Scheduler ==
 
== A Scheduler ==
 +
 +
A scheduler is like writing down a list of when you are going to do something and a state machine is like keeping a record of how far through a task you have got.
 +
 +
If you use the function delay(1000) then the processor goes away and does nothing for one second. We say this delay() is a blocking function, that is it blocks further activity in the program. So in order for our code to do something whilst waiting for the delay time to expire, what we need is a scheduler, something that will call a specific task at a specific time. There are several ways to do this but this is perhaps the simplest.
 +
 
== A State Machine ==
 
== A State Machine ==
  
  
 
A ‘state’ is the condition of a thing at a specific time. Something that can accomplish tasks and that utilizes states at its core is a state machine. They are also known as Finite State Machines (FSM), meaning that we know all possible states of the thing. The key to the state machine is the concept of time and history. The state of the machine is evaluated periodically. Each time it is evaluated, a new state is chosen (which could be the same state again), and the output is presented.
 
A ‘state’ is the condition of a thing at a specific time. Something that can accomplish tasks and that utilizes states at its core is a state machine. They are also known as Finite State Machines (FSM), meaning that we know all possible states of the thing. The key to the state machine is the concept of time and history. The state of the machine is evaluated periodically. Each time it is evaluated, a new state is chosen (which could be the same state again), and the output is presented.

Revision as of 00:40, 3 December 2018

Functions

Arrays and the for loop

Beyond the delay()

A Scheduler

A scheduler is like writing down a list of when you are going to do something and a state machine is like keeping a record of how far through a task you have got.

If you use the function delay(1000) then the processor goes away and does nothing for one second. We say this delay() is a blocking function, that is it blocks further activity in the program. So in order for our code to do something whilst waiting for the delay time to expire, what we need is a scheduler, something that will call a specific task at a specific time. There are several ways to do this but this is perhaps the simplest.

A State Machine

A ‘state’ is the condition of a thing at a specific time. Something that can accomplish tasks and that utilizes states at its core is a state machine. They are also known as Finite State Machines (FSM), meaning that we know all possible states of the thing. The key to the state machine is the concept of time and history. The state of the machine is evaluated periodically. Each time it is evaluated, a new state is chosen (which could be the same state again), and the output is presented.