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

Side by Side Diff: samples/raspberry_pi/basic/door-bell.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/buzzer.dart ('k') | samples/raspberry_pi/basic/knight-rider.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 door bell example. Illustrates watching GPIO pin state with events. 5 // A door bell example. Illustrates watching GPIO pin state with events.
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 import 'package:os/os.dart'; 12 import 'package:os/os.dart';
12 13
13 main() { 14 main() {
14 // GPIO pin constants. 15 // GPIO pin constants.
15 const int button = 16; 16 const int button = 16;
16 const int speaker = 21; 17 const int speaker = 21;
17 18
18 // Initialize GPIO and speaker pin. 19 // Initialize Raspberry Pi and configure the pins.
19 SysfsGPIO gpio = new SysfsGPIO(); 20 RaspberryPi pi = new RaspberryPi();
21 SysfsGPIO gpio = pi.sysfsGPIO;
22
23 // Initialize pins.
20 gpio.exportPin(speaker); 24 gpio.exportPin(speaker);
21 gpio.setMode(speaker, Mode.output); 25 gpio.setMode(speaker, Mode.output);
22
23 // Initialize button pin. Enable a button down trigger.
24 gpio.exportPin(button); 26 gpio.exportPin(button);
25 gpio.setMode(button, Mode.input); 27 gpio.setMode(button, Mode.input);
26 gpio.setTrigger(button, Trigger.both); 28 gpio.setTrigger(button, Trigger.both);
27 29
28 // Continuously monitor button. 30 // Continuously monitor button.
29 while (true) { 31 while (true) {
30 // Wait for button press. 32 // Wait for button press.
31 gpio.waitFor(button, true, -1); 33 gpio.waitFor(button, true, -1);
32 34
33 // Sound bell 35 // Sound bell
34 for (var i = 1; i <= 3; i++) { 36 for (var i = 1; i <= 3; i++) {
35 gpio.setPin(speaker, true); 37 gpio.setPin(speaker, true);
36 sleep(100); 38 sleep(100);
37 gpio.setPin(speaker, false); 39 gpio.setPin(speaker, false);
38 sleep(500); 40 sleep(500);
39 } 41 }
40 } 42 }
41 } 43 }
OLDNEW
« no previous file with comments | « samples/raspberry_pi/basic/buzzer.dart ('k') | samples/raspberry_pi/basic/knight-rider.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698