Sample applications

This page provides some simple applications directly based on electronic bricks library.

Bricks based applications

Devices based applications

Simple button

The led is on while the button is pressed and off when it is released.

state Idle {
   transition pressed -> LedOn
   event Button?press
   action Led!led_on ()
}
state LedOn {
   transition released -> Idle
   event Button?release
   action Led!led_off ()
}

Requirements

  • Button (1) [Default pin: D_9]
  • Led (1) [Default pin: D_8]

Source code

Simple buzzer

The buzzer plays an SOS signal.

state Wait {
   on entry Timer!timer_start (1000)
   on exit Timer!timer_start (50)       
   transition begin -> Fast
   event Timer?timer_timeout
   action end_motif = false
}

Requirements

  • Buzzer (1) [Default pin: D_8]

Source code

Simple LED

The led simply blink (default frequency is one second). Frequency might be easily modified with the property simply_led.frequency

state Running
{
   on entry Timer!timer_start (frequency)
   transition toggle -> Running
   event Timer?timer_timeout
   action Led!led_toggle ()
}

Requirements

  • Led (1) [Default pin: D_8]

Source code

Simple PWM

The led intensity is controlled by the rotation sensor. Note this application is based on PWM core library and can be use to control other stuff than a LED.

state Running {
   internal event m : RotSensor?rotation_value
   action Pwm!set_pwm_value (m.val / 4)
}

Requirements

  • Led (1) [Default pin: PWM_PIN_9]
  • Rotation sensor (1) -> [Default pin: A_4]

Source code

Simple screen

The screen diplays "Hello World"

state Run {
   on entry do
      LcdScreen!print_string ("Hello")
      LcdScreen!set_cursor (0, 1)
      LcdScreen!print_string ("World")
   end
}

Requirements

  • Lcd screen 1602 (1) [Default pins: D_10, D_11, D_12, D_13, A_0, A_1, A_2]

Source code

Simple sensor display

The screen displays the value of the sensor of your choice. Keep in mind that in this application, you have to use only one sensor at the time.

state Running {
   on entry LcdScreen!set_cursor (0, 1)
   transition refresh -> Running
   event m : TempSensor?temperature_value
   action do
      LcdScreen!print_value (m.val)
      LcdScreen!print_string ("    ")
   end
}

Requirements

  • Lcd screen 1602 (1) [Default pins: D_10, D_11, D_12, D_13, A_0, A_1, A_2]
  • (Sound / Light / Rotation / Temperature) sensor (1) [Default pin: A_4]

Source code

Simple sound sensor

The led toggle when a high sound is detected.

state Running {
   internal event m : SoundSensor?sound_value
   guard m.val > threshold
   action Led!led_toggle ()
}

Requirements

  • Sound sensor (1) [Default pin: A_4]
  • Led (1) [Default pin: D_8]

Source code

Simple tilt switch

The led toggle when the position of the tilt switch changes.

state Running
{
   internal switch event TiltSwitch?tilt_toggle
   action Led!led_toggle ()
}

Requirements

  • Tilt switch (1) [Default pin: D_9]
  • Led (1) [Default pin: D_8]

Source code

Simple water sensor

The led is on if the sensor detects water.

state Idle {
   transition wet -> LedOn
   event m : WaterSensor?wet
   action Led!led_on ()
}               
state LedOn {
   transition dry -> Idle
   event m : WaterSensor?dry
   action Led!led_off ()
}

Requirements

  • Water sensor (1) [Default pin: D_9]
  • Led (1) [Default pin: D_8]

Source code

Simple soft button

This is an example of use of soft button device. The LED turn in the opposite position when the button is simply pressed, blink fast after a double click and blink slow if a long press is detected.

Requirements

  • Button (1) [Default pin: D_9]
  • Led (1) [Default pin: D_8]

Source code