source: orbit/arduino/puzzlebox_orbit/puzzlebox_orbit.ino @ 1f70352

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since 1f70352 was 1f70352, checked in by AzureViolin <zhanghaotz@…>, 8 years ago

arduino fly Orbit

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2
3 Mimics the fade example but with an extra parameter for frequency. It should dim but with a flicker
4 because the frequency has been set low enough for the human eye to detect. This flicker is easiest to see when
5 the LED is moving with respect to the eye and when it is between about 20% - 60% brighness. The library
6 allows for a frequency range from 1Hz - 2MHz on 16 bit timers and 31Hz - 2 MHz on 8 bit timers. When
7 SetPinFrequency()/SetPinFrequencySafe() is called, a bool is returned which can be tested to verify the
8 frequency was actually changed.
9 
10 This example runs on mega and uno.
11 */
12
13#include <PWM.h>
14
15//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
16int IR = 11;                // the pin that the Infrared LED is attached to
17int ON = 172;         // 17.5us/26us = 172.3/256
18int OFF = 0;
19int32_t frequency = 38400; //frequency (in Hz)
20
21void innerCycle(int onTime, int offTime)
22{
23  pwmWrite(IR, ON);
24  delayMicroseconds(onTime);
25  pwmWrite(IR, OFF);
26  delayMicroseconds(offTime);
27}
28
29void innerCode()
30{
31  innerCycle(730,396); //(773 414)->824 450
32  innerCycle(730,396);
33  innerCycle(668,734); //(720 756)->757 773
34  innerCycle(337,403); //(382 418)->431 435
35  innerCycle(668,734);
36  innerCycle(668,734);
37  innerCycle(337,403);
38  innerCycle(668,734);
39  innerCycle(337,403);
40  innerCycle(668,734);
41  innerCycle(337,403);
42  innerCycle(668,734);
43  innerCycle(337,403);
44  innerCycle(668,734);
45  innerCycle(337,403);
46  innerCycle(337,403);
47  innerCycle(668,734);
48  innerCycle(668,734);
49  innerCycle(668,734);
50  innerCycle(337,403);
51  innerCycle(337,403);
52  innerCycle(668,734);
53  innerCycle(668,734);
54  innerCycle(668,734);
55  innerCycle(668,734);
56  innerCycle(668,734);
57  innerCycle(337,403);
58  innerCycle(337,403);
59  innerCycle(337,403);
60  innerCycle(337,403);
61  innerCycle(668,734);
62 
63}
64
65void outerCode6668()
66{
67  innerCode(); delay(66);
68  innerCode(); delay(66);
69  innerCode(); delay(66);
70  innerCode(); delay(80); 
71}
72
73void outerCode5335358()
74{
75  innerCode(); delay(51);
76  innerCode(); delay(36);
77  innerCode(); delay(36);
78  innerCode(); delay(51);
79  innerCode(); delay(36);
80  innerCode(); delay(51);
81  innerCode(); delay(80);
82}
83
84void outerCode5358()
85{
86  innerCode(); delay(51);
87  innerCode(); delay(36);
88  innerCode(); delay(51);
89  innerCode(); delay(80);
90}
91
92void outerCode53()
93{
94  innerCode(); delay(51);
95  innerCode(); delay(36);
96}
97 
98
99void setup()
100{
101  pinMode(13, OUTPUT);
102  digitalWrite(13,LOW);
103  //initialize all timers except for 0, to save time keeping functions
104  InitTimersSafe();
105
106  //sets the frequency for the specified pin
107  bool success = SetPinFrequencySafe(IR, frequency);
108 
109  //if the pin frequency was set successfully, turn pin 13 on
110  if(success) {
111    digitalWrite(13, HIGH);   
112  }
113}
114
115void loop()
116{
117  outerCode6668();  outerCode5335358();  outerCode5358();
118  outerCode6668();  outerCode5358();  outerCode5358();
119  outerCode6668();  outerCode5335358();  outerCode53();  outerCode5335358();  outerCode5358();
120  outerCode6668();  outerCode5335358();
121  outerCode6668();  outerCode5335358();  outerCode53();  outerCode5335358();  outerCode5358();
122  outerCode6668();  outerCode5335358();
123  outerCode6668();  outerCode5335358();  outerCode53();  outerCode5335358();  outerCode5358();
124  outerCode6668();  outerCode5335358();
125 
126  //use this functions instead of analogWrite on 'initialized' pins
127
128}
129
Note: See TracBrowser for help on using the repository browser.