SHOW:
|
|
- or go back to the newest paste.
1 | - | //Tina's Rocker Version but still has that playing bug!! |
1 | + | //Tina's Rocker Version that works |
2 | ||
3 | using System; | |
4 | using System.Collections; | |
5 | using System.Threading; | |
6 | using Microsoft.SPOT; | |
7 | using Microsoft.SPOT.Presentation; | |
8 | using Microsoft.SPOT.Presentation.Controls; | |
9 | using Microsoft.SPOT.Presentation.Media; | |
10 | using Microsoft.SPOT.Touch; | |
11 | ||
12 | using Gadgeteer.Networking; | |
13 | using GT = Gadgeteer; | |
14 | using GTM = Gadgeteer.Modules; | |
15 | using Gadgeteer.Modules.GHIElectronics; | |
16 | using System.Xml; | |
17 | using System.IO; | |
18 | using Gadgeteer.Modules.Seeed; | |
19 | ||
20 | ||
21 | - | namespace Gadgeteer_Weather_Crier_01 |
21 | + | namespace Gadgeteer_Weather_Crier_02 |
22 | { | |
23 | ||
24 | public partial class Program | |
25 | { | |
26 | ||
27 | - | string musicFile; |
27 | + | //string musicFile; |
28 | GT.StorageDevice usbStorage; | |
29 | - | // create a time based event robot to trigger repeated tasks |
29 | + | |
30 | - | //GT.Timer timer = new GT.Timer(60000, GT.Timer.BehaviorType.RunContinuously); |
30 | + | |
31 | FileStream stream; | |
32 | ArrayList musicFiles = new ArrayList(); | |
33 | ||
34 | // This method is run when the mainboard is powered up or reset. | |
35 | void ProgramStarted() | |
36 | { | |
37 | - | // jump to the StartWiFi method that starts the WiFi |
37 | + | |
38 | - | //StartWiFi(); |
38 | + | |
39 | // Initialize event handling robots | |
40 | - | // create a button watching robot to trigger things when the button is pressed |
40 | + | |
41 | - | button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed); |
41 | + | |
42 | ||
43 | - | button1.ButtonPressed+=new Button.ButtonEventHandler(button1_ButtonPressed); |
43 | + | //accelerometer threshold bump method |
44 | - | |
44 | + | |
45 | //accelerometer.EnableThresholdDetection(4.0, true, true, true, true, false, false); | |
46 | //accelerometer.RequestMeasurement(); | |
47 | - | // set the timer robot so it fires off a tick event |
47 | + | |
48 | - | //timer.Tick += new GT.Timer.TickEventHandler(timer_Tick); |
48 | + | |
49 | accelerometer.MeasurementComplete += new Accelerometer.MeasurementCompleteEventHandler(accelerometer_MeasurementComplete); | |
50 | - | |
50 | + | accelerometer.StartContinuousMeasurements(); |
51 | ||
52 | // music finished listening robot | |
53 | music.MusicFinished += new Music.MusicFinishedPlayingEventHandler(music_MusicFinished); | |
54 | music.SetVolume(255); | |
55 | - | //accelerometer threshold method |
55 | + | |
56 | // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging. | |
57 | Debug.Print("Program Running"); | |
58 | } | |
59 | ||
60 | void accelerometer_MeasurementComplete(Accelerometer sender, Accelerometer.Acceleration acceleration) | |
61 | { | |
62 | ||
63 | //Debug.Print(" X " + acceleration.X + " Y " + acceleration.Y + " Z " + acceleration.Z); | |
64 | ||
65 | if (acceleration.X > -0.25 && acceleration.X < 0.25 && usbStorage != null && !nowPlaying) | |
66 | { | |
67 | if (currentFile == 0) | |
68 | { | |
69 | Debug.Print("Starting the first audio track: currentFile = " + currentFile); | |
70 | } | |
71 | playTracks(); | |
72 | - | void button_ButtonPressed(Button sender, Button.ButtonState state) |
72 | + | |
73 | ||
74 | - | if (button.IsLedOn) |
74 | + | |
75 | ||
76 | - | accelerometer.StopContinuousMeasurements(); |
76 | + | |
77 | - | button.TurnLEDOff(); |
77 | + | |
78 | Debug.Print("USB STORAGE DIS-CONNECTED"); | |
79 | musicFiles.Clear(); | |
80 | usbStorage = null; | |
81 | - | accelerometer.StartContinuousMeasurements(); |
81 | + | |
82 | - | button.TurnLEDOn(); |
82 | + | |
83 | void usbHost_USBDriveConnected(UsbHost sender, GT.StorageDevice storageDevice) | |
84 | { | |
85 | Debug.Print("USB STORAGE CONNECTED"); | |
86 | usbStorage = storageDevice; | |
87 | ||
88 | musicFiles.Add("audio" + Path.DirectorySeparatorChar + "20120713 151953.mp3");//Good Morning | |
89 | - | Debug.Print(" X " + acceleration.X + " Y " + acceleration.Y + " Z " + acceleration.Z); |
89 | + | musicFiles.Add("audio" + Path.DirectorySeparatorChar + "20120713 152009.mp3");//It looks like |
90 | musicFiles.Add("audio" + Path.DirectorySeparatorChar + "20120713 152027.mp3");//It going to be mostly sunny | |
91 | - | if (acceleration.X < -0.25) |
91 | + | musicFiles.Add("audio" + Path.DirectorySeparatorChar + "20120713 152211.mp3");//Tomorrow |
92 | musicFiles.Add("audio" + Path.DirectorySeparatorChar + "20120713 152044.mp3");//There's a chance of a storm | |
93 | - | //do something |
93 | + | |
94 | - | if (!nowPlaying) |
94 | + | |
95 | ||
96 | - | StartPlayingWords(); |
96 | + | void playTracks() |
97 | { | |
98 | nowPlaying = true; | |
99 | ||
100 | - | else if (acceleration.X > 0.25) |
100 | + | stream = usbStorage.Open((String)musicFiles[currentFile], FileMode.Open, FileAccess.Read); |
101 | music.SetVolume(255); | |
102 | - | //stop |
102 | + | Debug.Print("Starting to play: " + (String)musicFiles[currentFile]); |
103 | - | if (!nowPlaying) |
103 | + | music.Play(stream); |
104 | while (music.IsBusy) | |
105 | - | StartPlayingWords(); |
105 | + | |
106 | // You can't call music.StopPlaying or set volume with this loop running. | |
107 | Thread.Sleep(10); | |
108 | } | |
109 | } | |
110 | ||
111 | void music_MusicFinished(Music sender) | |
112 | - | void button1_ButtonPressed(Button sender, Button.ButtonState state) |
112 | + | |
113 | ||
114 | - | accelerometer.Calibrate(); |
114 | + | Debug.Print("Track finished"); |
115 | ||
116 | nowPlaying = false; | |
117 | currentFile++; | |
118 | if (currentFile < musicFiles.Count - 1) | |
119 | { | |
120 | Debug.Print("Moving to next audio track: currentFile = " + currentFile); | |
121 | } | |
122 | else | |
123 | { | |
124 | Debug.Print("Resetting audio: currentFile = 0"); | |
125 | currentFile = 0; | |
126 | } | |
127 | } | |
128 | - | musicFiles.Add("straight" + Path.DirectorySeparatorChar + "20120713 151406.mp3"); |
128 | + | |
129 | - | //musicFiles.Add("straight" + Path.DirectorySeparatorChar + "20120713 151950.mp3"); |
129 | + | |
130 | - | //musicFiles.Add("straight" + Path.DirectorySeparatorChar + "20120713 151953.mp3"); |
130 | + |