Skip to main content

Posts

Arduino map function decimal places (floating point numbers)

The programming library available with the Arduino has an interesting interpolation function, the map function. Sadly, it returns only integers. As you might want to interpolate floating point numbers for some instrumentation routine, for example, the integer limitation may lend you into some low resolution results.
Fortunately, Arduino supports method overloading, and we can rewrite another map function to support floating point numbers. The new map function could be like this: float map(int x, double in_min, double in_max, double out_min, double out_max){  return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min; }
Recent posts

How much space emacs backup files are using...?

Every time I use emacs, it automatically saves a backup file which filename ends with "~".
From time to time, I issue a recursive find command to wipe out  (delete) every emacs backup file from my home folder.
find . -iname \*~ -exec rm -rfv {} \;
And everything is clean.

I do it strictly to clean things up... not for any disk space concern...  But I was wondering how much disk space those backup files are consuming...

So, instead of an rm command, I had executed a df and piped all to awk to summarize...
find . -iname \*~  -exec du -s {} \; | cut -f 1 | awk '{s+=$1} END {print s}'

This time all the emacs backup files were consuming only 1.6M, which isn't big deal... but I think it is better to get rid of them.

Extracting embedded images from SVG

With Inkscape, one can open and edit PDF files. But when the PDF comes with embedded images, the resulting SVG keeps the images as an embedded base64 encoded data. I wanted to extract those embedded images from the resulting SVG. But I didn't want to use the "export bitmap" option on Inkscape to extract those images, as within this way I wouldn't really know the original resolution besides the fact that Inkscape would re-encode the image data. So I wrote this one line to extract all images from one SVG.

i=1; grep data:image test.svg  | cut -d "," -f 2 | cut -d \" -f 1 |while read line ; do echo $line | base64 --decode >  $i.png ; i=$((i+1)); done 

Now, the kid's time

After my little experiment wit clay stop motion animation (link), I brought the camera home and showed the process to my kids... My older son wanted to give it a try... And here is his first movie.

Clay stop motion

A colleague from just the neighbor lab found an old webcam, which has no support (driver) for his Windows 7... He asked me to try to find a Windows 7 driver or some driver which make the cam work for him... As I use a Linux workstation, I've just plugged the camera into an USB port to see what do I get. The camera worked pretty nicely...So we've launched "Cheese" and grab some pictures of some clay that was laying around... It took less than 5 minutes to make this small animation...

https://youtu.be/KD4sKULZF_U
After that, he forgot the windows driver and he lent that camera to me to play with the kids.

Emptying an entire CVS directory tree

Another one on CVS.
Keeping old projects in which one would spend so much effort to do a full migration to another version control system than just learn to live with the CVS limitations makes you find some weird workarounds...
In CVS you can't rename a directory, you can't either remove a directory. Instead, you can remove all files in the directory tree you want to remove, and do a "CVS update -P" pruning empty directories.
So, how to easily empty an entire directory tree? The find has a "-not" operator which lets you make an inverse logic. For example, you can find -name CVS to locate the CVS control directories and find -not -name CVS to find files other than the CVS control directories.
Finally, to empty an entire directory, but not touching the CVS control files and folders, one could run the following line:
find . -not -name CVS -a -not -name Entries -a -not -name Root -a -not -name Repository -not -type d | xargs rm; cvs remove

Arduino without arduino IDE

It has been a long time since my last post about hardware or embedded software...
This one is just about a link to:
A Brief Tutorial on Programming the ATMega (Arduino) without Arduino Softwarehttp://brittonkerin.com/cduino/lessons.html

The part which had call my attention most was the lesson 11, on persistence storage using the EEPROM.
There are much more, it worst a careful the reading.