| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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/dartino-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 import 'package:raspberry_pi/raspberry_pi.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 // GPIO pin constants. | 14 // GPIO pin constants. |
| 15 const int button = 16; | 15 const int button = 16; |
| 16 const int speaker = 21; | 16 const int speaker = 21; |
| 17 | 17 |
| 18 // Initialize Raspberry Pi and configure the pins. | 18 // Initialize Raspberry Pi and configure the pins. |
| 19 RaspberryPi pi = new RaspberryPi(); | 19 RaspberryPi pi = new RaspberryPi(); |
| 20 PiMemoryMappedGPIO gpio = pi.memoryMappedGPIO; | 20 PiMemoryMappedGPIO gpio = pi.memoryMappedGPIO; |
| 21 gpio.setMode(button, Mode.input); | 21 gpio.setMode(button, Mode.input); |
| 22 gpio.setMode(speaker, Mode.output); | 22 gpio.setMode(speaker, Mode.output); |
| 23 | 23 |
| 24 // Map state of button to speaker in a continuous loop. | 24 // Map state of button to speaker in a continuous loop. |
| 25 while (true) { | 25 while (true) { |
| 26 bool buttonState = gpio.getPin(button); | 26 bool buttonState = gpio.getPin(button); |
| 27 gpio.setPin(speaker, buttonState); | 27 gpio.setPin(speaker, buttonState); |
| 28 } | 28 } |
| 29 } | 29 } |
| OLD | NEW |