MacOS Finder: Spaltenreihenfolge dauerhaft ändern
Die Reihenfolge der Spalten im MacOS Finder lässt sich einfach durch drag’n’drop den eigenen Bedürfnissen anpassen. Es ist jedoch zu beachten, dass sich die geänderte Reihenfolge stets nur auf das aktuelle Verzeichnis bezieht. Soll die aktuelle Reihenfolge für alle Ordner gelten, so ist der View Options Dialog via CMD + J
zu öffnen und nach dem Ändern der Reihenfolge unten der Button “Use as Defaults” zu drücken.
Aber: Das reicht in der Regel nicht! MacOS merkt sich Ordner-spezfifische Einstellungen in der, in jedem Ordner vorhandenen, Datei .DS_Store
. Und die in dieser Datei hinterlegten Einstellungen haben Vorrang vor den globalen Einstellungen, die via “Use as Defaults” eingestellt wurden (selbige werden in com.apple.finder.plist
abgelegt, just for the Nerds).
Das Vorgehen, das bei mir zu dauerhaftem Erfolg geführt hat, ist wie folgt:
- Reihenfolge der Spalten im Finder anpassen.
CMD + J
und dann “Use as defaults”.- Im Terminal
sudo find /Users/<username>/ -name .DS_Store -delete
eingeben, Return. Dies löscht alle(!).DS_Store
Dateien in allen Verzeichnissen. ACHTUNG! Eine Falscheingabe dieses Befehls kann zu ernsthaften Schäden am System führen. Wer nicht weiß, wie dieser Befehl funktioniert und was da genau passiert, BITTE LASSEN. - Finder neu starten: Entweder im terminal mit
killall Finder
oder mit Alt + Rechtsklick auf das Finder-Icon im Dock und dort dann “Relaunch” wählen.
Hernach sollten vom Finder alle Verzeichnisse mit den Spalten in der gewünschten Reihenfolge anzeigen.
How to convert 3MF files to stl format on a Lin*x machine (including Mac)
If you need to convert a 3MF file to STL format you may find that there is no really simple solution. I found this very useful blog post by Zebethyal that describes how the command line tool 3mf2stl
by Charles Shapiro can be compiled on a Mac to convert 3MF files to STL format. The required steps in all brevity:
- Install Homebrew
Open terminal and type (all in one line)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Hit return. Homebrew is downloaded and installed. - Install libzip
Type
brew install libzip
After hitting return, the libzip library will be installed. - Download 3mf2stl
Enter the following URL in your browser
https://github.com/lemgandi/3mf2stl
and download the 3mf2stl repository (green button to the right, download as ZIP).
Unzip the file to a directory, e.g.~/Documents/3mf2stl/
- Compile 3mf2stl
Change to this directory
cd ~/Documents/3mf2stl/
and type
make
Hit return. The code will be compiled.
If the compilation was successful you will have an executable named 3mf2stl
in this directory.
Usage is ./3mf2stl -i <input_file.3mf> -o <output_file.stl>
How to get rid of MacOS’ “one or more items can’t be changed because they are in use”
MacOS can be annoying, at times. In this case I was struggling with a video file that could not be copied, moved, or deleted because MacOS persistet on telling me it “can’t be changed because [it is] in use”; cf. this screenshot of the popup message.
The Continue-Button might suggest that MacOS would perform the action if I clicked it. But after clicking continue, I was asked for my admin-password, the file would seemingly get copied (or moved etc.), and finally, the copied (or moved file etc.) would be deleted.
It took a lot of searching until I, finally, came across the solution in this thread. I did not dig into the gory details of the cause but it has something to do with the so-called extended file attributes. You can see if a file has extended file attributes when you do a ls
in the terminal. If there is an @ on the right-hand side of the file permissions this file has extended attributes set. As was the case with my video file:
> ls
-rwxr-xr-x@ 1 zzz staff 42164199 Dec 19 18:58 MAH07541.MP4
Using the -l@
flag we can see the extended attributes that are set for the file:
> ls -l@
-rwxr-xr-x@ 1 zzz staff 42164199 Dec 19 18:58 MAH07541.MP4
com.apple.FinderInfo 32
So in my case it’s the com.apple.FinderInfo
attribute that was causing the problem. As soon as I deleted the extended attribute using
> xattr -d com.apple.FinderInfo MAH07541.MP4
everything was back to normal and the file could be copied, moved, or deleted.
Be careful when you are fiddling with the extended attributes since they can also store resources or essential file metadata. A user in the above mentioned thread says that it is “…always safe to delete com.apple.FinderInfo”. Well, that is something you will have to decide on your own.
How to restart iPhone 8 (Plus|X) when you can’t shut down
The process of restarting your iPhone has changed with the advent of the iPhone 8, iPhone 8 Plus or iPhone X.
Such a restart, or hard reset, is necessary if your iPhone is acting weird like you are not able to shut it down by long pressing the side button or you can’t start apps etc.
The force-reboot is no longer achieved by pressing the side and home button simultaneously. Now you have to use the following sequence:
- Press the volume up button once.
- Press the volume down button once.
- Press and hold the side button until the Apple logo appears (approx. ten seconds).
That’s it, your iPhone should reboot. In case you protect your iPhone using a PIN, which is recommended, you will have to enter your PIN after reboot.
Webhosting (nicht nur) für echte Kommandozeilen-Nerds
Ich hab’ sie alle durch, die Massen-Web-Hosting-Anbieter. Eine nicht vollständige Liste in zufälliger Reihenfolge: Host Europe, all-inkl, Strato, Hetzner, alfashosting, goneo, GoDaddy, Celeros usw. usf. Das könnte ein langer, langer, geradezu ausgesprochen langer Rant darüber werden, was in schöner Regelmässigkeit bei denen alles nicht funktioniert bzw. funktioniert hat. Aber da muß jeder seine eigenen Erfahrungen machen. Und es ist auch gar nicht auszuschließen, dass jeder der genannten Dienstleister seine passende Zielgruppe hat, für die alles, sagen wir mal, irgendwie und gefühlt läuft.
Für mich war jeder Webhoster-Wechsel immer mit der Hoffnung verbunden, nun jemanden gefunden zu haben, der sein Geschäft im Griff hat. Aber eigentlich gab es immer nur Variationen der bekannten Ärgernisse: Support mit durchwachsener Fachkenntnis, träge Reaktionszeiten, Standardformulierungen, Geschwindigkeitsprobleme und Security Issues. Gerade der letzte Hoster setzt mit seiner technischen Inkompetenz insbesondere im Bereich des Server Hardenings dem ganzen noch einmal eine unrühmliche Krone auf. Der Name sei nicht genannt denn hier soll niemand diskreditiert werden.
Ganz im Gegenteil: Ich möchte hier einen Webhosting-Anbieter hervorheben, nein, geradezu anpreisen, der mir über die letzten zwei Jahre extrem an’s Herz gewachsen ist. Und das nicht, weil ich besonders oft den Support gebraucht hätte. Das war nur einmal der Fall und es gab innerhalb von Minuten eine fachlich extrem versierte Antwort, die konkret auf mein Anliegen einging und sofort weiterhalf. Das allein hat beim Martyrium aus IVRs, bestenfalls halb gelesenen E-Mails und Antworten, die dann nur noch auf ein Viertel des ursprünglichen Anliegens eingehen, schon extremen Seltenheitswert.
Katze aus dem Sack: Es geht um uberspace.de. Aus meiner Sicht kein klassischer One-Klick-To-Happiness-Webhoster mit Klicki-Bunti-GUI, sondern eher was für technikaffine Maker, die den Umgang mit der Kommandozeile nicht scheuen. Man muß sicher kein Web-Guru oder Un*x-Admin sein, aber schonmal in der Shell gearbeitet zu arbeiten, hilft sicherlich bei der Einrichtung des eigenen Web-Space. Allein daran sieht man schon, dass uberspace irgendwie … anders ist. Positiv anders.
Ein anderes Beispiel: Wer auf der Kommandozeile seine Domains, Mail-User oder den SpamAssassin verwalten möchte, der braucht eine Dokumentation. Die gibt es in Form eines umfangreichen WIKIs, das meiner Meinung nach kaum Wünsche offen lässt. Und noch etwas fällt sofort auf, wenn man das WIKI oder auch die Webseite durchliest: Kompetenz pur. Und Überzeugung. Beispielsweise, was die Preise/Bezahlung anbelangt. Jeder entscheidet selber, wieviel er uberspace bezahlen möchte. Auch die Abhandlungen über den Verzicht auf die Lastschrift (bezahlt wird per Überweisung) oder ganz generell immer wieder die Erläuterungen, warum das Team von uberspace die Dinge so macht, wie sie sie machen, sind absolut lesenswert.
Es gibt kaum eine Text, eine Erläuterung oder sonst eine Stelle, an der ich nicht einen Haken machen könnte. Selbst im gerade durchforsteten Impressum gibt es wieder etwas, wovon sich andere Seitenbetreiber etwas abschneiden könnten. Die meisten klicken sich ihren Impressums-Sermon bei erecht24 oder sonst wo zusammen und klatschen dann diesen Text mit mehr oder weniger Verstand auf ihre Seite. Bei uberspace finden wir aber: “[…] In Sachen Linkhaftung sparen wir uns den sonst üblichen Disclaimer, der nach Meinung der meisten Juristen ohnehin keine Rechtswirksamkeit entfaltet. […]” Ita est!
Ich bin schlichtweg begeistert von uberspace und wünsche mir inständig, dass sie im Rahmen der eigenen Ansprüche und Wünsche prosperieren und damit allen, die einen wirklich richtig guten Webhosting-Dienstleister haben möchten, lange erhalten bleiben!
I18n: nullseite.de goes zeropage.io
The king is dead, long live the king!
I started my private blog Nullseite BOY 2008. Since then it experienced two rebrushes and got an accompanying offspring EOY 2015 – the zeropage. There is only so much spare time one can spent on blogging (and other stuff;-) so I decided to quit trying to curate two blogs at the same time. The Nullseite will diminish as I am in the process of migrating the most worthy Nullseite-Posts to the zeropage. This requires some tedious manual labour and will, thus, take some time. Stay tuned!
How to run Netgear ProSafe Utility on MacOS
Netgear is offering his switch management software “ProSafe Plus” for Windows. And for Windows only. Well, they just might have not noticed that there is at least one other very popular operating system in the market. Such things happen.
To still run ProSafe on a Mac and avoid the overhead involved by installing hardware virtualizing suits like “Parallels Desktop” or “VirtualBox”, I tried to use the compatibility layer software WINE to run ProSafe.
WINE
WINE requires XQuartz first, then Wine for MacOS can be installed. After that you can right click an arbitrary Windoze *.exe file and “open with…” Wine. Unfortunately, the ProSafe Plus Utility did not install smoothly. Had to restart the installation process a couple of times but could start the ProSafe Utility only once. Digging into Wine’s website winehq.org you will find that other users already reported about problems with the installation of ProSafe. To sum it up: No easy way this time. Let’s do it the hard way.
VirtualBox
The hard way means that you will have to use a hardware virtualizer like VirtualBox or Parallels Desktop. And, apparently, you will need Windoze. Luckily, I had an old Windoze 7 installation CD lying around. The first step is to install the free virtualizer VirtualBox by Oracle. The installation process is pretty straightforward and to just run the ProSafe Utility you should be fine with the standard settings suggested by the installer.
You will, most likely, have assigned an ISO-Image of your copy of Windoze during installation. After VirtualBox has been installed, start the Windoze Virtual Machine and get your copy of Windoze installed in the Virtual Machine. That might take some time. After successful installation of Windoze you can reboot, log into your Windoze account and install Netgear’s ProSafe Utility.
After installation of the ProSafe Utility fire it up and, if all went well, you might see a screen similar to the following one. The ProSafe utility scans the network and will list all discovered switches. My switch, a GS108PEv3, hast been found and I am, finally and after all that hassle, ready to configure the switch.
Nightlight Late-Night Edition

tl;dr A nightlight based on a reworked Thingiverse design with Arduino-controlled LED light effects, touch sensors, and a piezo buzzer humming the first notes from the Imperial march. Watch the video to see it in action. Detailed instructions start below video.
Bragging rights
The rocket nightlight was presented in the German MAKE magazine 06/2016 as a community project. Thank you! 🙂
The link or a click on the picture take you to the table of contents of issue 06/2016. If you have questions concerning this project do not hesitate to contact me! <foobar@zeropage.io>
Project Description
You can find a great design for a LED nightlight with various emblems or logos like Stormtrooper, Superman, Punisher, etc. on Thingiverse. This design is based on a 3D printed case with a transparent and extruded inlay of the emblem/logo in the lid. The case has a hole on the backside to have an external power supply feed the internal light source, e.g., an RGB light stripe or similar.
I reworked this design to create a nightlight that
- does not need an external power supply, i.e., has a plug and can be directly plugged into a wall socket
- has touch switches to easily adjust the brightness, light effects (or modes), colors etc.
- uses a piezo buzzer to acknowledge touch switch triggers and to play the first notes from the Imperial March when plugged into a socket (a little annoying, but can be switched off;-)
- utilizes a mounting platform for six RGB LEDs that can be easily inserted into the case
- fixes some minor issues in the original design (displaced inlay and mounting hole)
- comes with a variety of light effects like fixed colors, strobe, or cyclone chase
Payload
1 x Arduino Pro Mini 5V 16MHz // Merchants on eBay offer a plethora of pro minis. Take care when ordering: The pro mini is available as 3,3V and 5V as well as 8MHz and 16MHz versions. Moreover: Many vendors are located in China; shipping may take a long time to your home country.
1 x Piezo buzzer // One of these (eBay) should work.
1 x Power supply // I used this EMSA050120, 5 V-/1,2 A from Pollin to harvest the mains supply circuit and the plug.
4 x 3D printed part // These parts comprise a case, an LED holder, a plate (or lid) and an emblem/logo. You will find the 3D templates as STL files on Thingiverse.
6 x RGB LED // The WS2812b have a nice color range and are usually cheapest when bought as an LED stripe. I had some spare LEDs from another project. You can order them on eBay or here (1m stripe, Roboter Bausatz Shop).
4 x M5, 16mm counter-sunk screw
1 x Software // The software for the Arduino is available in my Nightlight Late-Night Edition repository on GitHub.
Moreover a Dremel or similar to cut open the mains adapter, pliers, rasps, wires, some metal splints for the touch sensors, and, of course, a soldering iron.
Nightlight 3D Parts
The nightlight consists of four 3D printed parts; cf. the sandwich picture showing the different layers.
From bottom to top: 1) Case to host the mains supply circuit, Arduino pro mini, piezo buzzer, LEDs, touch switches, cables, and the plug. 2) LED holder. 3) The top plate and 4) the extruded emblem inlay.
3D Part 1: The Case
The case from the original design was only 13mm high (inner height) and, thus, not tall enough to host the electronic parts. I had to import the STL file into SketchUp and stretch the case on the z-axis to an inner height of 25mm. That gave me just enough space to squeeze the LED holder above the mains supply circuit into the case and still have 2 or 3mm distance from the top plate. The more space you have between the LEDs and the plate, the better the light will be diffused. But I did not want the nightlight to be more bulky than necessary so 25mm inner height had to suffice.
Increasing the height was the easy part. Designing the plug holder on the backside of the case was more difficult. I first measured the dimensions of the plug as precise as possible, then started to design a plug holder with SketchUp.
It took a couple of iterations and an according number of test prints until, finally, the plug snapped into the plug holder with a satisfying “click”. The plug fits so tight that I consider it to be unremovable without destroying the case. And I may add that this is by design since we are dealing with 230V AC power and the nightlight must be impenetrable by adventurous kid’s hands.
The case was printed with black REC PLA at 210°, bed temperature 60°, no support, 0.16mm height, 1.2mm wall thickness, and 66% infill. It depends on your 3D printer’s bridging abilities if the plug holder will be ok without support. If unsure, print the case with support turned on.
3D Part 2: The LED Holder
I wanted the LEDs in the nightlight to be on a planar surface to get an even illumination. The idea was to construct an LED holder in SketchUp that tightly fits into the case without gluing, is rather stable, and has legs to stand on. The images show what I came up with.
Luckily, the LED holder nearly immediately matched all of the above mentioned criteria. I chose white innofil3D PLA for the print since a white background looked best behind the semi-transparent inlay.
3D Part 3: The top Plate
The plate was printed with black REC PLA and the same print parameters as for the case (210°, bed temperature 60°, no support, 0.16mm height, 1.2mm wall thickness) except that infill was set to 100%. I did not want any light to escape through the plate. With a proper number of top and bottom layers 100% infill with black PLA might be an extreme overkill but I played it safe.
With 100% infill the plate came out rock solid which has another advantage: Some parts might need to be sanded so that the extruded emblem/logo wil fit into the plate. The more solid your parts, the better they can be sanded.
3D Part 4: The Emblem/Logo
The extruded rocket inlay was printed with transparent innofil3D PLA. You will notice that “transparent” is in no way comparable to acrylic glass or alike. Moreover, parts printed with this PLA look yellowed; like they have been exposed for too long in the sun. Nonetheless, this kind of transparency is the best you can get with current fused deposition modelling (FDM) based desktop 3D printers and PLA. Nylon and other filament materials might yield better results but they are more difficult to print and handle.
Infill was set to 22%. You will see the honeycomb pattern, or whatever type of infill you chose in your slicer, with such a low infill value. But more infill also means losing transparency. I was fine with 22%.
Avengers assemble!
Let’s put the hardware together.
Complete the Plate
The transparent emblem/logo has to be merged with the plate. Depending on the design there might be a couple of “loose” parts from the plate print that need to be inserted into the emblem/logo first. Rasps and sanding paper are your best friend in this step since the parts will most likely not fit straight off the 3D printer. While 3D prints are usually pretty nice, there are limits to the precision you can expect from FDM prints. The rocket has only one loose part which is the round window. That one is pretty easy to insert. If not, rasp and apply mild force. Do not apply too much pressure to the small parts – they might break or damage the plate. If in doubt, sand more and re-try often. It will finally fit. If all loose parts are pushed in the emblem/logo you will want to merge the emblem/logo with the plate. That might need some sanding too. The small and tall middle wing of the rocket will most likely need some sanding. Be very careful since it can break off easily. Carefully push the transparent part into the plate. A vise or a hammer might come in handy, depending on how brave you are. This step requires patience.
Disassemble the Power Supply
As mentioned in the Payload-section I used a very cheap EMSA050120 power supply from Pollin to harvest the mains supply circuit and the plug. The case turned out to be very intractable and successfully resisted my attempts to pry it open it with a screw driver or pliers. I could have tried to pop it open in the vise but did not want to risk damaging the PCB/electronics inside. Well, let’s mill it open – Dremel time!
Caveat: Always mill with safety glasses and use protective gloves. The picture is just for demonstration purposes. Milling plastic produces foul-smelling, and most likely toxic, fumes. Do it outdoors. The picture in the middle shows the mains supply circuit along with the plug. In the next picture you can see the backside of the supply circuit with the big L- and N-conductance pads on the right-hand side of the PCB.
Solder Wires on Plug
The plug will be connected with solid copper cables to the L- and N-conductance pads of the mains supply circuit.
Before we can solder the cables two small plastic bars have to be removed from the plug. I use pliers to simply break them off. After that I start to solder the cables on the plug’s connection pads (to the left and right of the middle screw). Or I tried because this turns out to be an epic soldering fail. I try a dozen times but can’t get the, sorry, GODDAMMIT cables to solder-join with the pads. The pads literally refuse to be soldered! But resistance is futile and a couple of search engine queries later I seem to be wiser: The pads are made of stainless steel which is pretty hard to solder with normal tin-solder. If not impossible at all. What I need is soldering fluid, something like this (Conrad).
If you read the soldering fluid’s hazard notes, well, you do not really want to use this stuff: Serious chemical burns of skin and eyes, irritating to the respiratory system, and so on and so forth. Zinc chloride is no fun. Keep away from children! After some more failed attempts even with the soldering fluid I learned that the pads need much more heat to join forces with the cables than I was used from soldering usual electronics stuff. So, finally, I got two nice solder joints. FTW!
Drill Holes for Touch Sensors
It is always a good idea to think before you act. And I wish I’d done that before printing the case since I forgot to add two 4mm holes for the touch sensors on the right-hand side of the case! Facepalm! Printing the case again just because two holes were missing was not an option. But we are not only apt with additive but also with subtractive manufacturing: I drill the holes with a 3mm wood drill and get a perfect diameter after some minor rasping. PLA is fairly easy to drill, e.g. compared to acrylic glass. But you may have to lift the drill from time to time to remove excess plastic. Wood drills are designed to automatically forward the excess wood to the top of the drill and out of the drill hole. When you drill PLA or other plastic materials it tends to melt and get stuck on the drill. The slower you drill, the better. Applying some drops of water or sewing-machine oil is said to help (not tried so far).
Connect Mains Supply Circuit to Plug
In this step we connect the mains supply circuit to the plug and fix the circuit in the case.
First pop the plug into the case’s plug holder. Since the copper wires are pretty rigid it is a good idea to shorten and bend them properly before soldering the wires to the mains supply circuit.
Solder the mains supply circuit’s L-conductance pad to the brown copper wire. Repeat with the N-conductance pad and the blue wire. Finally, attach the mains supply circuit to the bottom of the case. You can see the black and red 5V power supply cables on the left-hand side of the mains supply circuit. We will use these later to power the LEDs and the Arduino microcontroller.
Attach LEDs to LED Holder
I decided to use six WS2812b LEDs and arranged them on the holder in a pattern that showed the most even illumination level during my tests. In case you’re a Lumen junkie there is enough room to cramp more LEDs on the holder. The LED strips usually come with sticky tape on their backside so gluing them on the holder is easy. After that I used 0.15mm enamelled copper wire to solder the connections between the +5V, GND and D
Prepare the Touch Sensors
This nightlight requires two touch sensors to control its various functions. The Arduino library ADCTouch makes it very easy to add touch sensors to a project. You can connect nearly everything that changes its capacity when touched to an arbitrary analogue pin of the microcontroller and have that thing act like a touch sensor. In this project I use two small metal splints that will be stuck and glued in the drilled holes on the right-hand side of the case. To connect the splints to the Arduino I have to solder wires to them. Since they are made of stainless steel, I have to use soldering fluid again. One drop on each splint, plenty of heat, a little tin solder, and some heat shrink tubing later the two touch sensors are ready.
Wire it up!
The Fritzing breadboard view shows how the electronic components are wired up to the Arduino pro mini.
You can choose different pins on the Arduino by adjusting the Arduino Sketch accordingly.
- +5V from the power mains supply circuit goes to the VCC pin while ground is connected to the GND pin on the Arduino.
- The piezo buzzer’s negative pole is connected to the GND pin, the positive pole to pin 12.
- The upper touch sensor goes to pin A0.
- The lower touch sensor goes to pin A2.
- The view shows symbolically only one LED, not the wiring of all six LEDs. The first LED’s Din is connected via a 220 Ohm resistor to pin 10. It is usually advised to use a resistor to cover power spikes that could harm the LEDs. VSS or +5V on the LED is connected to the VCC pin on the Arduino. VDD or ground on the LED is wired to the a GND pin.
That’s how it looks like when all components have been soldered and put into place in the case.
I used hot glue to paste the Arduino and the piezo buzzer on the case. The touch sensors were easier to attach with super glue.
Light and Diffusion
We need to diffuse the light that is emitted by the LEDs so that the transparent rocket is evenly illuminated. I already had some experience with diffusion materials from another project where I tried normal paper with different grammages, frosted acrylic glass, and Ripstop. The results were ok, but not perfect. I followed a hint that white baking paper yields good diffusion results. Unfortunately, I was not able to find white baking paper; only the usual brown one. Next I tried sandwich paper (sic!) and that’s what I found to work best when it comes to LED light diffusion. Of course, it depends on what you are building and especially, how much space there is between the LEDs and the material of the boundary layer. Try different materials and find the one that best suits your needs. However, I like the sandwich paper and, thus, taped a double layer on the backside of the plate. After that, the plate is screwed to the case with four black M5x16mm counter-sunk screws. I wanted screws with no imprint on the screw head but did not pay (enough) attention to the seller’s pictures on eBay. So, always take a very close look at what you intend to buy. 😉 NB: The screws have to cut their way through the holes in the case so it can get tedious to get them in. Use appropriate force. Moreover, the screw heads were bigger than expected so I had to widen the reception holes on the lid’s front side with a hand countersink.
Code is Poetry
All that hardware does not do anything without the proper software. We need a sketch (aka program) for the Arduino pro mini so the nightlight will do the things described in the project description. Two of the used libraries are worth mentioning: The awesome FastLED library to control the RGB LEDs. And the ADCTouch library to easily turn a cable or a splint into a touch sensor. The sketch makes use of the Arduino’s inbuild non-volatile EEPROM to store modes, colors, and other stuff that can be reloaded the next time the nighlight is powered up. The most complicated part of the code is handling the touch sensors. Both sensors react to short (1st function), middle-long (2nd function) and long touches (3rd function) and trigger different functions depending on the touch durations. Sounds complicated, but is not. Or is it?
Upper sensor
- Short touch. Increase brightness of LEDs until maximum is reached (17 steps). Then turn LEDs off.
- Middle-long touch. Immediately return brightness to lowest setting, i.e., one step above zero.
- Long touch. Toggle playing Imperial March on power-up on/off.
Lower sensor
- Short touch. Change color, speed, or whatever of current lighting mode.
- Middle-long touch. Switch to next light mode.
- Long touch. Immediately switch to first light mode, i.e., fixed color.
You can find the code in my Nightlight Late-Night Edition repository on GitHub.
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
// // Nightlight Late-Night Edition v1.3 // Copyright (C) 2016 Axel Dietrich <foobar@zeropage.io> // http://zeropage.io // // An Arduino controlled nightlight with WS2812b RGB LEDs, // touch sensor switches, a potpourri of nice lighting effects and a // quite ugly piezo Star Wars(R) intro. // // This program is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation, either version 3 of the License, or (at your option) // any later version. This program is distributed in the hope that it will be // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General // Public License for more details. You should have received a copy of the GNU // General Public License along with this program (file LICENSE). If not, see // <http://www.gnu.org/licenses/>. // // History // 1.3, 12.11.2016 // - Added new mode eWHITE that switches all LEDs to, yes, white. // 1.2, 13.09.2016 // - eSTROBE: Using EVERY_N_MILLISECONDS macro did not work. Rolled my own. // - Very long touching mode button did not work. Used wrong variable names. Fixed. // - eBREATH mode looks ugly on lower brightness settings. Changed amplitude. // 1.1, 12.09.2016 // - Usability: increase sensor 2nd function waiting time. one second is too short and might induce unwanted triggers. // - Usability: add 4 sec long touch (3rd function) for mode sensor to quickly jump to first mode. // - Removed unnecessary code from eBREATHE mode. // 1.0, 11.09.2016 // - Initial release. // #include <FastLED.h> // http://fastled.io/ #include <Streaming.h> // http://arduiniana.org/libraries/streaming/ #include <ADCTouch.h> // http://playground.arduino.cc/Code/ADCTouch #include <EEPROM.h> #define LED_DATA_PIN 10 #define LED_NUM_LEDS 6 #define LED_BRIGHTNESS_STEP_SIZE 15 #define LED_COLOR_STEP_SIZE 5 #define PIEZO_PIN 12 #define TSENSOR_BRIGHTNESS_PIN A0 #define TSENSOR_MODE_PIN A2 #define TSENSOR_BRIGHTNESS_2ND_FUNCTION_WAITING_TIME 1200 // in milliseconds #define TSENSOR_BRIGHTNESS_3RD_FUNCTION_WAITING_TIME 3000 // in milliseconds #define TSENSOR_MODE_2ND_FUNCTION_WAITING_TIME 1200 // in milliseconds #define TSENSOR_MODE_3RD_FUNCTION_WAITING_TIME 3000 // in milliseconds #define EEPROM_ADR_PLAY_IMPERIAL_MARCH 0 #define EEPROM_ADR_MASTER_BRIGHTNESS 1 #define EEPROM_ADR_MODE 2 #define EEPROM_ADR_FIXED_COLOR_INDEX 3 #define EEPROM_ADR_TWINKLES_PALETTE 4 #define EEPROM_ADR_STROBE_SPEED 5 #define EEPROM_ADR_RAINBOW_DELTA_HUE 6 #define EEPROM_ADR_RAINBOW_GLITTER_DELTA_HUE 7 #define EEPROM_ADR_CONFETTI_CHANCE 8 #define EEPROM_ADR_BEATS_PER_MINUTE 9 #define EEPROM_ADR_BREATHE_COLOR_INDEX 10 #define EEPROM_ADR_CYCLONE_COLOR_INDEX 11 #define IMPERIAL_MARCH_SPEED 2.5 // higher value = play faster #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define DEBUG 0 CRGB gLED[ LED_NUM_LEDS ]; CRGBPalette16 myPal = RainbowColors_p; enum gModes { eSTART_MODE, eFIXED_COLOR, eCOLOR_TWINKLES, eSTROBE, eRAINBOW, eRAINBOW_WITH_GLITTER, eCONFETTI, eBPM, eBREATHE, eCYCLONE, eWHITE, eEND_MODE }; enum gPiezoModes { eBRIGHTNESS_PIEZO, eMODE_PIEZO, e3RD_FUNC_PIEZO }; uint16_t gTouchBrightnessRef; uint16_t gTouchModeRef; bool gPlayImperialMarch = true; uint8_t gMasterBrightness = 120; uint8_t gCurrentMode = eFIXED_COLOR; uint8_t gFixedColorIndex = 0; uint8_t gTwinklesPalette = 0; uint8_t gStrobeSpeed = 100; uint8_t gRainbowDeltaHue = 7; uint8_t gRainbowGlitterDeltaHue = 7; uint8_t gConfettiChance = 80; uint8_t gBeatsPerMinute = 60; uint8_t gBreatheColorIndex = 0; uint8_t gCycloneColorIndex = 0; uint8_t gHue = 0; bool gPowerUp = true; // // forward declarations void fPiezoShortTouch( byte mode ); void fPiezoLongTouch( byte mode ); void setup( ) { if ( DEBUG ) { delay( 500 ); Serial.begin( 9600 ); Serial.setTimeout( 200 ); // 200ms should be enough } randomSeed( analogRead( 1 ) ); pinMode( PIEZO_PIN, OUTPUT ); // Fetch data from EEPROM gPlayImperialMarch = EEPROM.read( EEPROM_ADR_PLAY_IMPERIAL_MARCH ); if(gPlayImperialMarch<0||gPlayImperialMarch>1) gPlayImperialMarch = true; gMasterBrightness = EEPROM.read( EEPROM_ADR_MASTER_BRIGHTNESS ); gCurrentMode = EEPROM.read( EEPROM_ADR_MODE ); if ( gCurrentMode<(eSTART_MODE+1) || gCurrentMode>(eEND_MODE-1) ) gCurrentMode = eSTART_MODE + 1; gFixedColorIndex = EEPROM.read( EEPROM_ADR_FIXED_COLOR_INDEX ); // for eFIXED_COLOR gTwinklesPalette = EEPROM.read( EEPROM_ADR_TWINKLES_PALETTE ); // for eCOLOR_TWINKLES gStrobeSpeed = EEPROM.read( EEPROM_ADR_STROBE_SPEED ); // for eSTROBE gRainbowDeltaHue = EEPROM.read( EEPROM_ADR_RAINBOW_DELTA_HUE ); // for eRAINBOW gRainbowGlitterDeltaHue = EEPROM.read( EEPROM_ADR_RAINBOW_GLITTER_DELTA_HUE ); // for eRAINBOW_WITH_GLITTER gConfettiChance = EEPROM.read( EEPROM_ADR_CONFETTI_CHANCE ); // for eCONFETTI gBeatsPerMinute = EEPROM.read( EEPROM_ADR_BEATS_PER_MINUTE ); // for eBPM gBreatheColorIndex = EEPROM.read( EEPROM_ADR_BREATHE_COLOR_INDEX ); // for eBREATHE gCycloneColorIndex = EEPROM.read( EEPROM_ADR_CYCLONE_COLOR_INDEX ); // for eCYCLONE fChoosePalette( gTwinklesPalette ); // FastLED setup FastLED.addLeds< WS2812B, LED_DATA_PIN, GRB >( gLED, LED_NUM_LEDS ); FastLED.setCorrection( TypicalLEDStrip ); FastLED.setBrightness( 0 ); fill_solid( gLED, LED_NUM_LEDS, CRGB::Black ); FastLED.show( ); if ( gPlayImperialMarch ) fPlayImperialMarch( ); // Touch wire setup. Create reference values to account for the capacitance of control wires. gTouchBrightnessRef = ADCTouch.read( TSENSOR_BRIGHTNESS_PIN, 500 ); gTouchModeRef = ADCTouch.read( TSENSOR_MODE_PIN, 500 ); // Welcome to the pleasure dome! if ( DEBUG ) { Serial << endl << endl << F( "Welcome to Nightlight Late-Night Edition v1.3" ) << endl; Serial << F( "(C) 2016 Axel Dietrich <foobar@zeropage.io>" ) << endl; Serial << F( "Type h for a list of commands." ) << endl; } } void loop( ) { static uint16_t lastMillisBrightness = millis( ); static uint16_t lastMillisMode = millis( ); static bool touchedBrightness = false; static bool touchedMode = false; static bool mustReleaseBrightnessSensor = false; static bool mustReleaseModeSensor = false; bool shortModeTouch = false; // Check if touch sensors have been activated. // Get Touch values. int touchBrightnessVal = ADCTouch.read( TSENSOR_BRIGHTNESS_PIN ); int touchModeVal = ADCTouch.read( TSENSOR_MODE_PIN ); // Remove offset computed in setup() touchBrightnessVal -= gTouchBrightnessRef; touchModeVal -= gTouchModeRef; // Touch too much? // Check the BRIGHTNESS touch sensor. // short touch => increase brightness by LED_BRIGHTNESS_STEP_SIZE // long touch => set brightness to lowest value (i.e. night mode) // very long touch => toggle playing imperial march on boot if ( touchBrightnessVal > 40 ) { if ( !touchedBrightness ) touchedBrightness = true; // Check if touch sensor touched for at least TSENSOR_BRIGHTNESS_2ND_FUNCTION_WAITING_TIME milliseconds. uint16_t m = millis( ); if ( !mustReleaseBrightnessSensor ) { if ( ( m - lastMillisBrightness ) > TSENSOR_BRIGHTNESS_2ND_FUNCTION_WAITING_TIME ) { // a long touch => set brightnes to lowest value lastMillisBrightness = m; gMasterBrightness = 10; FastLED.setBrightness( gMasterBrightness ); FastLED.show( ); EEPROM.write( EEPROM_ADR_MASTER_BRIGHTNESS, gMasterBrightness ); fPiezoLongTouch( eBRIGHTNESS_PIEZO ); mustReleaseBrightnessSensor = true; } } else if ( ( m - lastMillisBrightness ) > TSENSOR_BRIGHTNESS_3RD_FUNCTION_WAITING_TIME ) { // a very long touch => toggle playing imperial march lastMillisBrightness = m; EEPROM.write( EEPROM_ADR_PLAY_IMPERIAL_MARCH, ( gPlayImperialMarch ? 0 : 1 ) ); fPiezoLongTouch( e3RD_FUNC_PIEZO ); } } else { if ( touchedBrightness ) { // We get here when brightness touch sensor was touched and released. touchedBrightness = false; if ( mustReleaseBrightnessSensor ) { // ah, brightness touch sensor released after a long touch mustReleaseBrightnessSensor = false; } else { // a short touch => gradually increase brightness gMasterBrightness = ( (gMasterBrightness + LED_BRIGHTNESS_STEP_SIZE) > 255 ? 0 : (gMasterBrightness + LED_BRIGHTNESS_STEP_SIZE) ); FastLED.setBrightness( gMasterBrightness ); FastLED.show( ); EEPROM.write( EEPROM_ADR_MASTER_BRIGHTNESS, gMasterBrightness ); if ( gMasterBrightness == (255-LED_BRIGHTNESS_STEP_SIZE) ) fPiezoShortTouch( eBRIGHTNESS_PIEZO ); if ( gMasterBrightness == 255 ) fPiezoShortTouch( eBRIGHTNESS_PIEZO ), fPiezoShortTouch( eBRIGHTNESS_PIEZO ); fPiezoShortTouch( eBRIGHTNESS_PIEZO ); } } lastMillisBrightness = millis( ); } // Touch too much? // Check the MODE touch sensor. // short touch => function depends on mode // long touch => switch to next mode // very long touch => jump to the first mode if ( touchModeVal > 40 ) { if ( !touchedMode ) touchedMode = true; // Check if touch sensor touched for at least TSENSOR_MODE_2ND_FUNCTION_WAITING_TIME milliseconds. uint16_t m = millis( ); if ( !mustReleaseModeSensor ) { if ( ( m - lastMillisMode ) > TSENSOR_MODE_2ND_FUNCTION_WAITING_TIME ) { // a long touch => switch to the next mode byte noOfModes = eEND_MODE - eSTART_MODE - 1; gCurrentMode = ( gCurrentMode<noOfModes ? gCurrentMode+1 : eSTART_MODE+1 ); lastMillisMode = m; mustReleaseModeSensor = true; fPiezoLongTouch( eMODE_PIEZO ); } } else if ( ( m - lastMillisMode ) > TSENSOR_MODE_3RD_FUNCTION_WAITING_TIME ) { // a very long touch => jump to the first mode lastMillisMode = m; gCurrentMode = eSTART_MODE + 1; fPiezoLongTouch( e3RD_FUNC_PIEZO ); } } else { if ( touchedMode ) { // We get here when mode touch sensor was touched and released. touchedMode = false; if ( mustReleaseModeSensor ) { // ah, mode touch sensor released after a long touch mustReleaseModeSensor = false; EEPROM.write( EEPROM_ADR_MODE, gCurrentMode ); } else { // a short touch => depends on mode what happens fPiezoShortTouch( eMODE_PIEZO ); shortModeTouch = true; } } lastMillisMode = millis( ); } switch ( gCurrentMode ) { case eFIXED_COLOR: { static bool firstTimeAfterBoot = true; if ( shortModeTouch ) { gFixedColorIndex = ( (gFixedColorIndex + LED_COLOR_STEP_SIZE) > 255 ? 0 : (gFixedColorIndex + LED_COLOR_STEP_SIZE) ); fill_solid( gLED, LED_NUM_LEDS, ColorFromPalette( myPal, gFixedColorIndex ) ); FastLED.show( ); EEPROM.write( EEPROM_ADR_FIXED_COLOR_INDEX, gFixedColorIndex ); } if (firstTimeAfterBoot||mustReleaseModeSensor) { fill_solid( gLED, LED_NUM_LEDS, ColorFromPalette( myPal, gFixedColorIndex ) ); FastLED.show( ); firstTimeAfterBoot = false; } } break; case eCOLOR_TWINKLES: if ( shortModeTouch ) { fNextPalette( ); EEPROM.write( EEPROM_ADR_TWINKLES_PALETTE, gTwinklesPalette ); } fTwinkle( ); FastLED.show( ); break; case eSTROBE: { static bool strobesSet = false; static uint16_t lastMillis = millis( ); byte maxLEDsOn = ((int)(LED_NUM_LEDS/2)) + 1; gStrobeSpeed = max( gStrobeSpeed, 10 ); gStrobeSpeed = min( gStrobeSpeed, 100 ); if ( shortModeTouch ) { gStrobeSpeed = ( gStrobeSpeed>10 ? gStrobeSpeed-10 : 100 ); EEPROM.write( EEPROM_ADR_STROBE_SPEED, gStrobeSpeed ); Serial << "gStrobeSpeed " << gStrobeSpeed << endl; } if ( !strobesSet ) { for( byte i = 0; i < maxLEDsOn; i++ ) { gLED[ random( LED_NUM_LEDS ) ] = CRGB::White; FastLED.show( ); } strobesSet = true; } // hm. EVERY_N_MILLISECONDS did not work here so have to roll my own. uint16_t m = millis( ); if ( ( m - lastMillis ) > gStrobeSpeed ) { if ( strobesSet ) { fill_solid( gLED, LED_NUM_LEDS, CRGB::Black ); strobesSet = false; } lastMillis = m; } FastLED.show( ); } break; case eRAINBOW: { byte start = 7; byte stepSize = 3; gRainbowDeltaHue = max( gRainbowDeltaHue, start ); if ( shortModeTouch ) { gRainbowDeltaHue = ( gRainbowDeltaHue<(start+10*stepSize) ? gRainbowDeltaHue+stepSize : start ); EEPROM.write( EEPROM_ADR_RAINBOW_DELTA_HUE, gRainbowDeltaHue ); } fill_rainbow( gLED, LED_NUM_LEDS, gHue, gRainbowDeltaHue ); FastLED.show( ); } break; case eRAINBOW_WITH_GLITTER: { byte start = 7; byte stepSize = 3; gRainbowGlitterDeltaHue = max( gRainbowGlitterDeltaHue, start ); if ( shortModeTouch ) { gRainbowGlitterDeltaHue = ( gRainbowGlitterDeltaHue<(start+10*stepSize) ? gRainbowGlitterDeltaHue+stepSize : start ); EEPROM.write( EEPROM_ADR_RAINBOW_GLITTER_DELTA_HUE, gRainbowGlitterDeltaHue ); } fill_rainbow( gLED, LED_NUM_LEDS, gHue, gRainbowGlitterDeltaHue ); if ( random8( ) < 80 ) // 30% chance of glitter gLED[ random16( LED_NUM_LEDS ) ] += CRGB::White; FastLED.show( ); } break; case eCONFETTI: { byte start = 80; byte stepSize = 10; gConfettiChance = max( gConfettiChance, start ); if ( shortModeTouch ) { gConfettiChance = ( gConfettiChance<(start+10*stepSize) ? gConfettiChance+stepSize : start ); EEPROM.write( EEPROM_ADR_CONFETTI_CHANCE, gConfettiChance ); } fadeToBlackBy( gLED, LED_NUM_LEDS, 10 ); if ( random8( ) < gConfettiChance ) gLED[ random16( LED_NUM_LEDS ) ] += CHSV( gHue + random8( 64 ), 200, 255 ); FastLED.show( ); } break; case eBPM: { byte startBeats = 60; byte stepSize = 5; gBeatsPerMinute = max( gBeatsPerMinute, startBeats ); gBeatsPerMinute = min( gBeatsPerMinute, startBeats+15*stepSize ); if ( shortModeTouch ) { gBeatsPerMinute = ( gBeatsPerMinute<(startBeats+15*stepSize) ? gBeatsPerMinute+stepSize : startBeats ); EEPROM.write( EEPROM_ADR_BEATS_PER_MINUTE, gBeatsPerMinute ); } uint8_t beat = beatsin8( gBeatsPerMinute, 64, 255); for ( int i = 0; i < LED_NUM_LEDS; i++ ) gLED[ i ] = ColorFromPalette( PartyColors_p, gHue+(i*2), beat-gHue+(i*10) ); FastLED.show( ); } break; case eBREATHE: { static byte counter = 0; if ( shortModeTouch ) { gBreatheColorIndex = ( (gBreatheColorIndex + LED_COLOR_STEP_SIZE) > 255 ? 0 : (gBreatheColorIndex + LED_COLOR_STEP_SIZE) ); fill_solid( gLED, LED_NUM_LEDS, ColorFromPalette( myPal, gBreatheColorIndex ) ); FastLED.show( ); EEPROM.write( EEPROM_ADR_BREATHE_COLOR_INDEX, gBreatheColorIndex ); } byte brightness = quadwave8( 3*(counter++) ); // quadwave8() is nearly a sine wave but 2/3 faster than sin8() fill_solid( gLED, LED_NUM_LEDS, ColorFromPalette( myPal, gBreatheColorIndex, brightness ) ); FastLED.show( ); if ( brightness > 254 ) FastLED.delay( 50 ); } break; case eCYCLONE: { static byte index = 0; if ( shortModeTouch ) { gCycloneColorIndex = ( (gCycloneColorIndex + LED_COLOR_STEP_SIZE) > 255 ? 0 : (gCycloneColorIndex + LED_COLOR_STEP_SIZE) ); fill_solid( gLED, LED_NUM_LEDS, ColorFromPalette( myPal, gCycloneColorIndex ) ); FastLED.show( ); EEPROM.write( EEPROM_ADR_CYCLONE_COLOR_INDEX, gCycloneColorIndex ); } EVERY_N_MILLISECONDS( 80 ) { gLED[ index ] = ColorFromPalette( myPal, gCycloneColorIndex ); FastLED.show( ); fadeToBlackBy( gLED, LED_NUM_LEDS, 50 ); index = ( index < (LED_NUM_LEDS-1) ? index+1 : 0 ); } } break; case eWHITE: { static bool firstTimeAfterBoot = true; if (firstTimeAfterBoot||mustReleaseModeSensor) { fill_solid( gLED, LED_NUM_LEDS, CRGB( 255, 255, 255 ) ); // set all LEDs to white FastLED.show( ); firstTimeAfterBoot = false; } } break; default: break; } // slowly cycle the "base color" through the rainbow EVERY_N_MILLISECONDS( 20 ) { gHue++; } // fade in to master brightness when nightlight is plugged into socket. static byte fadeInBrightness = 0; if ( gPowerUp ) { if ( fadeInBrightness<gMasterBrightness ) { fadeInBrightness += 5; EVERY_N_MILLISECONDS( 10 ) { FastLED.setBrightness( fadeInBrightness ); FastLED.show( ); } } else gPowerUp = false; } // Check for serial command. if ( DEBUG ) { byte ch; if ( Serial.available( ) ) { switch ( ch = Serial.read( ) ) { case 'b': { // b{0..255} set brightness while ( !Serial.available( ) ) {} byte brightness = Serial.parseInt( ); brightness = ( brightness > 255 ? 255 : brightness ); FastLED.setBrightness( brightness ); FastLED.show( ); break; } case 'h': fShowHelp( ); break; case 'p': { // p{0..255} set LEDs to color from palette myPal while ( !Serial.available( ) ) {} byte index = Serial.parseInt( ); index = ( index > 255 ? 255 : index ); fill_solid( gLED, LED_NUM_LEDS, ColorFromPalette( myPal, index ) ); FastLED.show( ); break; } case 'R': // soft reset, does not reset peripherals and registers asm volatile (" jmp 0"); break; default: // none break; } } } // EOF check for serial command } // // Functions // // ===================================================================================== // Color twinkle lights by Mark Kriegsman. // https://gist.github.com/kriegsman/5408ecd397744ba0393e #define STARTING_BRIGHTNESS 64 #define FADE_IN_SPEED 28 #define FADE_OUT_SPEED 20 #define DENSITY 128 CRGBPalette16 mkG_Palette; CRGB r(CRGB::Red), R(0xA80016), w(85,85,85), W(CRGB::White), l(0xE1A024); CRGBPalette16 mkG_allPalettes[] = { CRGBPalette16( r,r,r,r, R,R,R,R, r,r,r,r, R,R,R,R ), // Red, Burgundy CRGBPalette16( l,l,l,l, l,l,l,l, l,l,l,l, l,l,l,l ), // Incandescent "fairy lights" //LavaColors_p, ForestColors_p, CRGBPalette16( 0x000000, 0x250000, 0x4A0000, 0x6F0000, // Variation of HeatColors_p with no white and less yellow 0x940000, 0xB90000, 0xDE0000, 0xFF0000, 0xFF2500, 0xFF4A00, 0xFF6F00, 0xFF9400, 0xFFB900, 0xFFDE00, 0xFFFF00, 0x250000 ), CRGBPalette16( W,W,W,W, w,w,w,w, w,w,w,w, w,w,w,w ) // Snow }; void fChoosePalette( byte paletteNumber ) { paletteNumber = min( paletteNumber, ARRAY_SIZE(mkG_allPalettes)-1 ); // sanity check mkG_Palette = mkG_allPalettes[ paletteNumber ]; } void fNextPalette( ) { gTwinklesPalette = ( gTwinklesPalette < (ARRAY_SIZE(mkG_allPalettes)-1) ? gTwinklesPalette+1 : 0 ); fChoosePalette( gTwinklesPalette ); } enum { eGETTING_DARKER = 0, eGETTING_BRIGHTER = 1 }; void fTwinkle( ) { // Make each pixel brighter or darker, depending on // its 'direction' flag. fBrightenOrDarkenEachPixel( FADE_IN_SPEED, FADE_OUT_SPEED) ; // Now consider adding a new random twinkle if( random8() < DENSITY ) { int pos = random16( LED_NUM_LEDS ); if( !gLED[ pos ]) { gLED[pos] = ColorFromPalette( mkG_Palette, random8( ), STARTING_BRIGHTNESS, NOBLEND ); fsetPixelDirection( pos, eGETTING_BRIGHTER ); } } } void fBrightenOrDarkenEachPixel( fract8 fadeUpAmount, fract8 fadeDownAmount ) { for( uint16_t i = 0; i < LED_NUM_LEDS; i++) { if( fGetPixelDirection( i ) == eGETTING_DARKER ) { // This pixel is getting darker gLED[i] = fMakeDarker( gLED[i], fadeDownAmount ); } else { // This pixel is getting brighter gLED[i] = fMakeBrighter( gLED[i], fadeUpAmount ); // now check to see if we've maxxed out the brightness if( gLED[i].r == 255 || gLED[i].g == 255 || gLED[i].b == 255) { // if so, turn around and start getting darker fsetPixelDirection( i, eGETTING_DARKER ); } } } } CRGB fMakeBrighter( const CRGB& color, fract8 howMuchBrighter ) { CRGB incrementalColor = color; incrementalColor.nscale8( howMuchBrighter ); return color + incrementalColor; } CRGB fMakeDarker( const CRGB& color, fract8 howMuchDarker) { CRGB newcolor = color; newcolor.nscale8( 255 - howMuchDarker ); return newcolor; } uint8_t gDirectionFlags[ (LED_NUM_LEDS+7) / 8]; bool fGetPixelDirection( uint16_t i) { uint16_t index = i / 8; uint8_t bitNum = i & 0x07; return bitRead( gDirectionFlags[index], bitNum ); } void fsetPixelDirection( uint16_t i, bool dir ) { uint16_t index = i / 8; uint8_t bitNum = i & 0x07; bitWrite( gDirectionFlags[index], bitNum, dir); } // // show help in serial monitor void fShowHelp( ) { Serial << F( "=====================================================" ) << endl; Serial << F( "COMMANDS" ) << endl; Serial << F( "h This help." ) << endl; Serial << F( "b{0..255} Set LED master brightness." ) << endl; Serial << F( "p{0..255} Set LEDs to color from (green,yellow,red) palette." ) << endl; Serial << F( "R Reset Arduino. Does not reset peripherals and registers." ) << endl; Serial << F( "=====================================================" ) << endl; } // // Bells'n'whistles! Play first notes from Star Wars Imperial March when the nightlight is plugged in. // c/o https://gist.github.com/tagliati/1804108 void fPlayImperialMarch( ) { fBeep( 440, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 440, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 440, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 349, (long)(350/IMPERIAL_MARCH_SPEED) ); fBeep( 523, (long)(150/IMPERIAL_MARCH_SPEED) ); fBeep( 440, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 349, (long)(350/IMPERIAL_MARCH_SPEED) ); fBeep( 523, (long)(150/IMPERIAL_MARCH_SPEED) ); fBeep( 440, (long)(800/IMPERIAL_MARCH_SPEED) ); delay( 100 ); fBeep( 659, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 659, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 659, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 698, (long)(350/IMPERIAL_MARCH_SPEED) ); fBeep( 523, (long)(150/IMPERIAL_MARCH_SPEED) ); fBeep( 415, (long)(500/IMPERIAL_MARCH_SPEED) ); fBeep( 349, (long)(350/IMPERIAL_MARCH_SPEED) ); fBeep( 523, (long)(150/IMPERIAL_MARCH_SPEED) ); fBeep( 440, (long)(1000/IMPERIAL_MARCH_SPEED) ); } // // play a tone on piezo speaker with specific frequency and duration void fBeep( int frequencyInHertz, long timeInMilliseconds ) { long delayAmount = (long)( 1000000 / frequencyInHertz ); long loopTime = (long)( ( timeInMilliseconds*1000 ) / ( delayAmount*2 ) ); for ( int x = 0; x < loopTime; x++ ) { digitalWrite( PIEZO_PIN, HIGH ); delayMicroseconds( delayAmount ); digitalWrite( PIEZO_PIN, LOW ); delayMicroseconds( delayAmount ); } delay( 20 ); // a little delay to make all notes sound separate } // // play this when one of the touch wire buttons is briefly touched void fPiezoShortTouch( byte mode ) { int note = ( mode == eBRIGHTNESS_PIEZO ? 3000 : 1000 ); fBeep( note, 2 ); } // // play this when one of the touch wire buttons is touched for a longer time (triggering its 2nd function) void fPiezoLongTouch( byte mode ) { switch ( mode ) { case eBRIGHTNESS_PIEZO: fBeep( 240, 2 ); fBeep( 880, 5 ); fBeep( 1600, 9 ); break; case eMODE_PIEZO: fBeep( 120, 2 ); fBeep( 440, 5 ); fBeep( 800, 9 ); break; default: /* e3RD_FUNC_PIEZO */ fBeep( 5000, 15 ); delay( 20 ); fBeep( 5000, 15 ); delay( 20 ); fBeep( 5000, 15 ); delay( 20 ); fBeep( 5000, 15 ); break; } } |
Ready Player One
That was a real fun project and the roket nightlight turned out to be a full success!
Sep 2016, i.f.
Lord Overhaul: How to fix a rake’s missing wing nut
Our rake lost its wing nut that is used to fix the pusher for the blades.
On first inspection I thought, that I just take any other M5 wing nut and that thing is good for another ten years of gardening service. But far wrong. The ISO metric screw threads (Wikipedia) come in different pitches: fine, middle, and coarse (at least in Germany). The thread in the rake must be either middle or coarse. At least none of my fine nuts fits on the thread.
So what now? Make or buy? Buy a couple of wing nuts? Buy a new rake? Of course not. Let’s replace the screw with a M5 fine pitched one.
First step: Pry open the lid. Done. Second step: Remove the old screw. Not an easy task since the manufacturer first drilled a hole and then pushed or hammered the screw through the hole so it stuck really, really tight. After a couple of miserable attempts to remove it with pliers I realized that there is only one appropriate tool for this job: A hammer. The evil screw is out.
Let’s see how we get the new screw attached to the lid. Soldering stainless steel is difficult. Welding would surely work but is somewhat impossible without weldering equipment. Last resort: Glue! Hot glue, not durable enough. The same might apply to super glue. But two-component power putty should be fine.
Funny thing: I do have nuts, but no wing nuts! Duh! So let’s print a wing nut using the awesome Ultimate Nut Knob Generator (Thingiverse) by wstein. Here it is.
I super glued a washer on the outer side so the PLA will not be squashed or damaged when the wing nut is tightened. Now it’s time to put the pieces back together.
Avengers assemble!
All set and done. Let the gardening begin!
Ultimaker 2+ Low Friction Spool Holder with Bearings
The spool holder shipped with the Ultimaker2+ is ok and with the new extruder there should be no issues with underextrusion. Depending on the size and type of the filament spool you might encounter squeaking noises from time to time. Surely not serious enough an issue to substitute the spool holder. But what if a spool does not fit on the spool holder and gets completely jammed? That’s what exactly happened with a spool from REC. Time for a new spool holder!
sneakypoo designed a nice bearing based Low friction spool holder and put it on Thingiverse. Thank you! The spool holder requires five 3D printed parts together with two bearings, a threaded rod and a couple of nuts. It comes in two different lengths for big and not so big spools as well as two different diameters to either fit 626 or 608 bearings.
I printed the short 608 version which is sufficient for standard 750g filament spools. The holder is very well designed and everything fit perfectly. Except the spacer which was too long so I had to rasp it down by approximately 4-5mm. A couple of commenters already pointed that out on Thingiverse. So trust them (or me, or all of us) and shrink the spacer in your slicer prior to printing!
The following picture shows the order in which the parts have to be assembled.
The assembled spool holder.
And the new spool holder attached to the Ultimaker.
Check sneakypoo’s video to see what low friction looks like in real life. Awesome!
That thing is virtually noiseless and gives real Jesus gliding action. Luv it!