Ada provides an extensive set of capabilities for creating programs with concurrent code modules (tasks), for real-time programming, similar to Java threads. Those tasks are executed concurrently with the rest of the program, so I thought the best way to test them on a Raspberry Pi is by blinking two LEDs at different time intervals ;)
Accessing the GPIO pins on a Raspberry Pi from an Ada program requires a library, I'm using Linux Simple I/O Library by Philip Munts.
Assuming we have two LEDs (and corresponding resistors) on GPIO17 and 18, here's the source code for blinking them at different intervals, using tasks.
Note: Ada logo source Ada Belgium
Accessing the GPIO pins on a Raspberry Pi from an Ada program requires a library, I'm using Linux Simple I/O Library by Philip Munts.
Assuming we have two LEDs (and corresponding resistors) on GPIO17 and 18, here's the source code for blinking them at different intervals, using tasks.
-- -- GPIO LED Test using libsimpleio -- task version -- WITH Ada.Text_IO; USE Ada.Text_IO; WITH GPIO.libsimpleio; PROCEDURE blinky_tasks IS LED_red : GPIO.Pin := GPIO.libsimpleio.Create(0, 17, GPIO.Output); LED_green : GPIO.Pin := GPIO.libsimpleio.Create(0, 18, GPIO.Output); Ch : Character; Available : Boolean; task First_task; task Second_task; task body First_task is begin LOOP LED_red.Put(True); delay 1.5; LED_red.Put(False); delay 1.5; exit when Available = True; END LOOP; end First_task; task body Second_task is begin LOOP LED_green.Put(True); delay 0.5; LED_green.Put(False); delay 0.5; exit when Available = True; END LOOP; end Second_task; BEGIN Put_Line("GPIO LED Test using libsimpleio - task version"); New_Line; Put_Line("press any key to exit..."); LOOP Get_Immediate(Ch, Available); exit when Available = True; END LOOP; LED_red.Put(False); LED_green.Put(False); END blinky_tasks;
Note: Ada logo source Ada Belgium
Comments
Post a Comment