Attachment 'Light_Time_Switch.ino'

Download

   1 /*
   2  Author    : Loe Feijs
   3  Date      : 20130302
   4  
   5  This example shows how to control a LED (LED via 470 Ohm 
   6  between pin 9 and GND). The light goes on when the button 
   7  switch is pushed. Switch between GND and pin 2. The light 
   8  source goes off after 4 seconds (programmed as a finite 
   9  state machine).
  10  */
  11 
  12 //connect LED, Button:
  13 #define ledPin 9 
  14 #define buttonPin 2
  15 
  16 //FSM states:
  17 #define OFF 0
  18 #define ON  1
  19 
  20 // initialisation
  21 int state = OFF;
  22 int timer = 0;
  23 
  24 void setup()  { 
  25   pinMode(ledPin, OUTPUT); 
  26   pinMode(buttonPin, INPUT_PULLUP);
  27 } 
  28 
  29 void loop()  { 
  30   LEDstep();
  31   delay(10); // one step every 10 ms
  32 }
  33 
  34 /*
  35 Finite state machine implementation
  36  */
  37 void LEDstep(){
  38 
  39   switch (state){
  40   case OFF:
  41     if (digitalRead(buttonPin) == LOW){
  42       // change state
  43       state = ON;
  44       // state transition actions
  45       timer = 400; // 10 millisecond steps 
  46       analogWrite(ledPin,255); // max brightness
  47     }  
  48     break;
  49   case ON: 
  50     if (timer <= 0){
  51       // change state
  52       state = OFF;
  53       // state transition actions
  54       analogWrite(ledPin,0);
  55     } 
  56     else timer--;
  57     break;
  58   }
  59 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2015-12-20 02:08:32, 1586.5 KB) [[attachment:AlgorithmsAndDataStructures.pdf]]
  • [get | view] (2015-12-20 02:08:32, 327.3 KB) [[attachment:AlgorithmsAndDataStructures_examples.zip]]
  • [get | view] (2015-12-20 02:08:32, 1186.9 KB) [[attachment:ArduinoAndSerialCommunication.pdf]]
  • [get | view] (2015-12-20 02:08:32, 3212.2 KB) [[attachment:ArduinoAndSerialCommunication.pptx]]
  • [get | view] (2015-12-20 02:08:32, 2650.4 KB) [[attachment:Arduino_sheets.pdf]]
  • [get | view] (2015-12-20 02:08:32, 578.3 KB) [[attachment:ArraysAndFunctions.pdf]]
  • [get | view] (2015-12-20 02:08:32, 18.2 KB) [[attachment:ArraysAndFunctions_examples.zip]]
  • [get | view] (2015-12-20 02:08:32, 1.0 KB) [[attachment:DrawingCreatures.zip]]
  • [get | view] (2015-12-20 02:08:32, 583.5 KB) [[attachment:FSM_sheets.pdf]]
  • [get | view] (2015-12-20 02:08:33, 3768.5 KB) [[attachment:GSArduino.pdf]]
  • [get | view] (2015-12-20 02:08:33, 151.8 KB) [[attachment:GUIExamples.zip]]
  • [get | view] (2015-12-20 02:08:32, 1248.8 KB) [[attachment:Graphics.pdf]]
  • [get | view] (2015-12-20 02:08:33, 4715.7 KB) [[attachment:GraphicsIntroduction.pdf]]
  • [get | view] (2015-12-20 02:08:33, 2.3 KB) [[attachment:Graphics_Exercises.zip]]
  • [get | view] (2015-12-20 02:08:33, 344.9 KB) [[attachment:GuiAndInteractivity.pdf]]
  • [get | view] (2015-12-20 02:08:33, 324.3 KB) [[attachment:Introduction.pdf]]
  • [get | view] (2015-12-20 02:08:33, 353.5 KB) [[attachment:IoT.pdf]]
  • [get | view] (2015-12-20 02:08:33, 1023.3 KB) [[attachment:IoT2013Q3.pdf]]
  • [get | view] (2015-12-20 02:08:33, 46.6 KB) [[attachment:IoT2013Q3Examples.zip]]
  • [get | view] (2015-12-20 02:08:33, 113.7 KB) [[attachment:IoTExamples.zip]]
  • [get | view] (2015-12-20 02:08:33, 258.2 KB) [[attachment:IoT_Examples.zip]]
  • [get | view] (2015-12-20 02:08:33, 1055.1 KB) [[attachment:IoT_lecture.pdf]]
  • [get | view] (2015-12-20 02:08:33, 2215.0 KB) [[attachment:IoT_lecture.pptx]]
  • [get | view] (2015-12-20 02:08:33, 2.7 KB) [[attachment:Light_Time_LDR_Fade.ino]]
  • [get | view] (2015-12-20 02:08:33, 1.1 KB) [[attachment:Light_Time_Switch.ino]]
  • [get | view] (2015-12-20 02:08:33, 5.7 KB) [[attachment:Multimedia_examples.pdf]]
  • [get | view] (2015-12-20 02:08:33, 5.7 KB) [[attachment:Multimedia_examples_WS03.zip]]
  • [get | view] (2015-12-20 02:08:34, 5423.2 KB) [[attachment:OOCSI_in_Processing.pdf]]
  • [get | view] (2015-12-20 02:08:33, 863.2 KB) [[attachment:ObjectOrientation.pdf]]
  • [get | view] (2015-12-20 02:08:33, 3.1 KB) [[attachment:ObjectOrientation_examples_BouncingBalls.pde]]
  • [get | view] (2015-12-20 02:08:33, 1.4 KB) [[attachment:ObjectOrientation_examples_Cars.pdf]]
  • [get | view] (2015-12-20 02:08:33, 1.4 KB) [[attachment:ObjectOrientation_examples_Cars.zip]]
  • [get | view] (2015-12-20 02:08:33, 1.6 KB) [[attachment:ObjectOrientation_examples_EPD.pdf]]
  • [get | view] (2015-12-20 02:08:33, 1.6 KB) [[attachment:ObjectOrientation_examples_EPD.zip]]
  • [get | view] (2015-12-20 02:08:33, 0.8 KB) [[attachment:ObjectOrientation_examples_Earth.pdf]]
  • [get | view] (2015-12-20 02:08:33, 0.8 KB) [[attachment:ObjectOrientation_examples_Earth.zip]]
  • [get | view] (2015-12-20 02:08:33, 1.3 KB) [[attachment:ObjectOrientation_examples_Planets.pdf]]
  • [get | view] (2015-12-20 02:08:33, 1.3 KB) [[attachment:ObjectOrientation_examples_Planets.zip]]
  • [get | view] (2015-12-20 02:08:34, 76.4 KB) [[attachment:RegistrationList.pdf]]
  • [get | view] (2015-12-20 02:08:34, 73.0 KB) [[attachment:RegistrationList.xls]]
  • [get | view] (2015-12-20 02:08:34, 2080.5 KB) [[attachment:UsingLibraries.pdf]]
  • [get | view] (2015-12-20 02:08:34, 1176.2 KB) [[attachment:VariablesAndFlowControl.pdf]]
  • [get | view] (2015-12-20 02:08:32, 2.9 KB) [[attachment:bouncingBalls.pde]]
  • [get | view] (2015-12-20 02:08:32, 276.9 KB) [[attachment:examples.jpg]]
  • [get | view] (2015-12-20 02:08:32, 35.3 KB) [[attachment:examples320.jpg]]
  • [get | view] (2015-12-20 02:08:34, 21.4 KB) [[attachment:oocsi_processing_library.zip]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.