Pages

Monday, December 10, 2012

A more complex Arduino sketch using QP

I've built an application that monitors digital input and controls digital outputs using the asynchronous event driven state machine from Quantum Leaps (also see my previous posts on this platform). I wanted to test the feasibility of using this platform for an Arduino application that doesn't use the standard loop() method to poll inputs.

The project blinks one LED continuously while a passive infrared sensor triggers another LED to flash when motion is first detected (edge trigger). A green LED tracks the state of a switch, and if the switch is on when the PIR senses motion, the controller runs a vibrator module for 1 second. The code consumes about 8K.

The inputs and outputs are setup as linked lists so adding additional IO to this project would be trivial. This project only deals with binary digital inputs and outputs. I plan to look into PWM outputs and analog inputs next, so I expect Project 2 to build on this one, just as this one was build from the simple event and publish projects.

There are three running "processes"; a digital input controller, a logic controller and a digital output controller. The digital input controller scans a linked list of inputs every 10 ms and publishes an event for each one that changes. The logic controller subscribes to these input events and uses a simple state/event check to determine what outputs are to be changed. The controller then publishes events that the digital output controller uses to change the outputs on 10 ms intervals.

Not all of the outputs are under direct control of the logic controller. In the case of the blinking LED the output controller is making is blink directly.

The qp_Project_1.zip file is here:

http://code.google.com/p/quantum-leaps-arduino-light/downloads/list

Again I would like to note that I am not associated with this company. and I'm not an expert on this platform. I've only started using it a few weeks ago.

No comments:

Post a Comment