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 // A small buzzer example illustrating both input and output GPIO pins. | 5 // A small buzzer example illustrating both input and output GPIO pins. |
6 // | 6 // |
7 // For breadboard layout and connections to the Pi, see: | 7 // For breadboard layout and connections to the Pi, see: |
8 // https://storage.googleapis.com/fletch-archive/images/buzzer-schematic.png | 8 // https://storage.googleapis.com/fletch-archive/images/buzzer-schematic.png |
9 | 9 |
10 import 'package:gpio/gpio.dart'; | 10 import 'package:gpio/gpio.dart'; |
| 11 import 'package:raspberry_pi/raspberry_pi.dart'; |
11 | 12 |
12 main() { | 13 main() { |
13 // GPIO pin constants. | 14 // GPIO pin constants. |
14 const int button = 16; | 15 const int button = 16; |
15 const int speaker = 21; | 16 const int speaker = 21; |
16 | 17 |
17 // Initialize GPIO and configure the pins. | 18 // Initialize Raspberry Pi and configure the pins. |
18 PiMemoryMappedGPIO gpio = new PiMemoryMappedGPIO(); | 19 RaspberryPi pi = new RaspberryPi(); |
| 20 PiMemoryMappedGPIO gpio = pi.memoryMappedGPIO; |
19 gpio.setMode(button, Mode.input); | 21 gpio.setMode(button, Mode.input); |
20 gpio.setMode(speaker, Mode.output); | 22 gpio.setMode(speaker, Mode.output); |
21 | 23 |
22 // Map state of button to speaker in a continuous loop. | 24 // Map state of button to speaker in a continuous loop. |
23 while (true) { | 25 while (true) { |
24 bool buttonState = gpio.getPin(button); | 26 bool buttonState = gpio.getPin(button); |
25 gpio.setPin(speaker, buttonState); | 27 gpio.setPin(speaker, buttonState); |
26 } | 28 } |
27 } | 29 } |
OLD | NEW |