OLD | NEW |
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 // | 4 // |
5 // The 'hello world' of embedded: Blinking an LED. Uses the on-board | 5 // The 'hello world' of embedded: Blinking an LED. Uses the on-board |
6 // Raspberry Pi 2 activity LED. | 6 // Raspberry Pi 2 activity LED. |
7 | 7 |
8 import 'package:gpio/gpio.dart'; | 8 import 'package:gpio/gpio.dart'; |
| 9 import 'package:raspberry_pi/raspberry_pi.dart'; |
9 import 'package:os/os.dart'; | 10 import 'package:os/os.dart'; |
10 | 11 |
11 main() { | 12 main() { |
12 // Constant for the Raspberry Pi 2 onboard green LED. | 13 // Initialize Raspberry Pi and configure the activity LED to be GPIO |
13 const int led = 47; | 14 // controlled. |
14 | 15 RaspberryPi pi = new RaspberryPi(); |
15 // Initialize gpio and configure the pin. | 16 pi.leds.activityLED.setMode(OnboardLEDMode.gpio); |
16 PiMemoryMappedGPIO gpio = new PiMemoryMappedGPIO(); | |
17 gpio.setMode(led, Mode.output); | |
18 | 17 |
19 // Turn LED on and off in a continuous loop. | 18 // Turn LED on and off in a continuous loop. |
20 while (true) { | 19 while (true) { |
21 gpio.setPin(led, true); | 20 pi.leds.activityLED.on(); |
22 sleep(500); | 21 sleep(500); |
23 gpio.setPin(led, false); | 22 pi.leds.activityLED.off(); |
24 sleep(500); | 23 sleep(500); |
25 } | 24 } |
26 } | 25 } |
OLD | NEW |