Ik ben een Sims plumbob lamp (https://www.thingiverse.com/thing:4770371) aan't maken voor een nicht van me (ze speelt nogal veel The Sims zodus), maar ik zit een beetje vast met een aantal effecten en 1 daarvan is als je de lamp afzet dan dimt ie tot 0 maar als je de lamp aanzet moet die natuurlijk terug in faden.
Het uitfaden lukt (lijn 83 tot 89) dus ik dacht, laat ik de code omdraaien (optellen in de plaats van aftellen) en dat is dan klaar.
yeah right.
Bij het aanzetten duurt het even voor de lamp aangaat en zit ineens op het maximum dat is ingesteld.
Hardware in gebruik:
- Arduino nano
- knop met condensator over tussen gnd en pin3
- 28 SK6812 RGBW neopixel achter elkaar op pin 2
- 5V van de pc usb
Ik dacht eerst dat de functie niet werd uitgevoerd maar bij het aanzetten gaat ie er wel degelijk door, dit door Serial.println(i); in die loop (zie lijn 66)
Het uitfaden lukt (lijn 83 tot 89) dus ik dacht, laat ik de code omdraaien (optellen in de plaats van aftellen) en dat is dan klaar.
yeah right.
Bij het aanzetten duurt het even voor de lamp aangaat en zit ineens op het maximum dat is ingesteld.
Hardware in gebruik:
- Arduino nano
- knop met condensator over tussen gnd en pin3
- 28 SK6812 RGBW neopixel achter elkaar op pin 2
- 5V van de pc usb
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
| #include <NeoPixelBrightnessBus.h> //#include <NeoPixelAnimator.h> niet gebruikt in dit stuk code #include <avr/sleep.h> #define DATA_PIN 2 #define button 3 //this is what ever pin you have hooked up to the button. I used an arduino nano, and it has an internal pull up resistor the other side of the button should be wired to ground #define RainbowDelay 25 #define RainbowBrightness 60 #define colorSaturation 255 // saturation of color constants /*** Button states & timer **/ volatile uint32_t ButtonTimer = 0; boolean ButtonActive = false; boolean LongPressActive = false; boolean MediumPressActive = false; boolean OffState=true; boolean BackFromSleep=false; /*** Pixel and brightness settings ***/ const uint8_t PixelCount = 28; // make sure to set this to the number of pixels in your strip unit8_t = max 255 pixels const uint8_t c_MinBrightness = 8; const uint8_t c_MaxBrightness = 255; const RgbwColor black(0); uint8_t LastBrightness=128; /*** Animation stuff ***/ uint8_t Animation = 1; uint8_t LastAnimation=0; NeoGamma<NeoGammaTableMethod> colorGamma; // for any fade animations, best to correct gamma NeoPixelBrightnessBus<NeoGrbwFeature, NeoSk6812Method > strip(PixelCount, DATA_PIN); void setup() { Serial.begin(115200); //gebruik ik als debug functie strip.Begin(); SetRandomSeed(); strip.SetPixelColor(PixelCount-1, RgbwColor(HslColor(random(360) / 360.0f, 1.0f, 0.2f))); strip.Show(); delay(500); strip.SetPixelColor(PixelCount-1, black); strip.Show(); strip.SetBrightness(LastBrightness); pinMode(button, INPUT_PULLUP);//setting up the button } void loop() { /** Button short/long presses **/ /* https://www.instructables.com/Arduino-Dual-Function-Button-Long-PressShort-Press/ */ if (digitalRead(button) == LOW) { if (ButtonActive == false) { if(OffState)//came back from a off state { LastAnimation=0; Serial.println("Lights on"); for (uint8_t i = 8; i <LastBrightness ; i++) { delay(15); strip.SetBrightness(i); strip.Show(); Serial.println(i); } strip.SetBrightness(LastBrightness); strip.Show(); Serial.println("Offstate end"); } LongPressActive = false; ButtonActive = true; ButtonTimer = millis(); } // check for long press if ((millis() - ButtonTimer >= 5000) && (LongPressActive == false)) { LongPressActive = true; Serial.println("Lights off"); //shut off the lights with a fade and get ready to sleep LastBrightness= strip.GetBrightness(); for (uint8_t i = LastBrightness; i > c_MinBrightness ; i--) { delay(15); strip.SetBrightness(i); strip.Show(); } /** setting up deep sleep **/ ButtonTimer = millis(); OffState=true; } }else{ if(ButtonActive == true && LongPressActive == false) { if(BackFromSleep==false && OffState==false) { Animation++; if(Animation >= 12){Animation = 1;} } BackFromSleep=false; OffState=false; } LongPressActive = false; ButtonActive = false; } if(OffState==false)//jump over it when in offstate { /** Do the animations if any**/ if(LastAnimation!=Animation) { switch (Animation) { case 1:Red();break; case 2:Green();break; case 3:Blue();break; case 4:Yellow();break; case 5:White();break; } LastAnimation=Animation; } strip.Show(); } }//end of check offstate /** give 5 to 10s before going to deep sleep **/ if ((millis() - ButtonTimer > 5000) && OffState) { /* https://thekurks.net/blog/2018/1/24/guide-to-arduino-sleep-mode */ Serial.println("Sleep mode activated :zzzzzzzz"); delay(1000);//only needed to dump the serial sleep_enable(); attachInterrupt(0,WakeUp,LOW); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_cpu(); } } void WakeUp() { sleep_disable(); detachInterrupt(0); Serial.println("Target practice :x"); BackFromSleep=true; } void Red() { for (uint16_t i = 0; i < PixelCount; i++) { strip.SetPixelColor(i, RgbwColor(colorSaturation,0,0,0)); } strip.Show(); } void Green() { for (uint16_t i = 0; i < PixelCount; i++) { strip.SetPixelColor(i, RgbwColor(0,colorSaturation,0,0)); } strip.Show(); } void Blue() { for (uint16_t i = 0; i < PixelCount; i++) { strip.SetPixelColor(i, RgbwColor(0,0,colorSaturation,0)); } strip.Show(); } void Yellow() { for (uint16_t i = 0; i < PixelCount; i++) { strip.SetPixelColor(i, RgbwColor(colorSaturation,colorSaturation,0,0)); } strip.Show(); } void White() { for (uint16_t i = 0; i < PixelCount; i++) { strip.SetPixelColor(i, RgbwColor(255)); } strip.Show(); } |
Ik dacht eerst dat de functie niet werd uitgevoerd maar bij het aanzetten gaat ie er wel degelijk door, dit door Serial.println(i); in die loop (zie lijn 66)
Al wat ik aanraak werk niet meer zoals het hoort. Damic houd niet van zijn verjaardag