Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: samples/raspberry_pi/basic/buzzer.dart

Issue 1389573002: Refactor Raspberry Pi GPIO and add GPIO mock (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: Remove unused constant Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samples/raspberry_pi/basic/blinky.dart ('k') | samples/raspberry_pi/basic/door-bell.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
OLDNEW
« no previous file with comments | « samples/raspberry_pi/basic/blinky.dart ('k') | samples/raspberry_pi/basic/door-bell.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698