EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #160 background imageLoading...
Page #160 background image
end
-
print '0' * (8 - (image.columns % 8))
-
puts ','
-
end
-
20
puts '};'
-
First, the program loads the rmagick library and imports the RMagick
namespace. We do this to save some typing, because now we dont have to
fully qualify all classes that live in the RMagick namespace. In line 4, we read
an image whose name we have to pass as a command-line argument. The
image files format doesnt matter, because ImageMagick understands nearly
all image file formats. The
image
variable contains a representation of the
image that doesnt depend on the original file format any longer.
Next, we output the first three lines of the C++ file wed like to generate. These
lines are mostly static. Only the third line contains some variable partsthat
is, the images width and the height.
Then we process the images pixels using two nested loops. The outer loop
iterates through each row of the image, and the inner loop through each col-
umn. In line 13 we read the current pixel, and in the next line we use a cheap
trick to determine whether the pixel is black or white. We know that our
images consist only of black and white pixels, so its sufficient to check only
one color component. If the red component is 0, the pixel has to be black. If
its 1, the pixel has to be white. We transform every pixel into a bit value, and
if the number of pixels in an image row isnt divisible by 8 without a remainder,
we fill the remaining bits with zeros.
You can run the program like this:
maik> ruby img2cpp.rb thermometer.png > thermometer.cpp
This call turns the
thermometer.png
file into a C++ file you can add to your
Arduino project without any further modifications. Thats how software
developers approach boring and error-prone tasks.
In the next chapter, youll learn how to connect a Wii Nunchuk to your
Arduino, and well use the TVout library to turn the Arduino into a video game
console.
What If It Doesnt Work?
Even if this chapters hardware is simple, a few things can still go wrong. If
you dont see a video signal at all on your TV set, make sure youve selected
report erratum discuss
What If It Doesnt Work? 143
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino Pro Mini and is the answer not in the manual?

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals