{"id":300,"date":"2007-02-24T18:58:57","date_gmt":"2007-02-24T18:58:57","guid":{"rendered":"http:\/\/diversifiedcuriosities.com\/2007\/02\/24\/cylon-detector\/"},"modified":"2017-08-18T18:03:01","modified_gmt":"2017-08-18T18:03:01","slug":"cylon-detector","status":"publish","type":"post","link":"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/","title":{"rendered":"The Ersatz Cylon Detector: A Hardware Sketch To Illuminate The Inner Workings of the MAX6953 Integrated Circuit"},"content":{"rendered":"

\"Cylon<\/a><\/p>\n

An on-going project that requires the display of alphabetic and numeric characters using a 5×7 LED matrix turned me towards a chip by Maxim IC<\/a> \u2014 the MAX6953<\/a>. The chip, while expensive (~$8), has lots of built-in features that mitigate the damage to my purse, trading such in kind for time-saved. It will directly drive up to 4 5×7 LED matrices<\/a> with direct control from a microcontroller over a two-wire interface (TWI\/I2C)<\/a>, can manage varying intensities (16 or 32 degree scales), has a built-in Arial-like font set with a reasonably full-range of characters, diacritics and symbols, and allows me to create 24 characters of my own design.<\/p>\n

Here’s my Eagle PCB library of the MAX6951 and MAX6953<\/a>; feel free to use it.<\/p>\n

\n\"SlowMessenger_Max6953_Breakout\"<\/a><\/p>\n

\n

\"SlowMessenger_Max6953_Breakout_Board\"<\/a><\/p>\n

\n

My first attempt at mucking with the chip used the DIP version, which is ginormous and requires such patience and diligence with wiring the thing up \u00e2\u20ac\u201d\u00c2 all those lines going to the pins of the LED matrix \u00e2\u20ac\u201d that I pretty much gave up after it didn’t work the first time. I decided that I’d just go ahead and design a PCB for the thing and continue to hone my skills with Eagle<\/a>, while also learning how to work with the MAX6953.<\/p>\n

\"\"<\/a><\/p>\n

\"\"<\/a><\/p>\n

\"\"<\/a><\/p>\n

\"Some<\/a><\/p>\n

I sent a design off<\/a>, it came back, I stared at it for a few minutes, looked for the MAX6953’s in my bin of samples and realized I didn’t have any. I managed to coax a bunch from Maxim’s sample guy, which is great. (Thanks whoever you are, wherever you are.) A couple of weeks later, when my plate was relatively clear, I assembled one of the boards, using a yellowish\/orange 5×7 matrix LED<\/a> I purchased from Digikey<\/a> and manufactured by LiteOn<\/a>. I wanted small, but the closest I got to small was 0.7″, which still seems big to me. (The story of it’s assembly<\/a> and problems therein is instructive if you’re curious about surface-mount PCB work..and the problems therein.)<\/p>\n

I powered the thing up and, naturally enough, it didn’t illuminate at all. I poked through the spec sheet and figured out that there’s a whole start-up ritual you’ll want to go through, such as the test mode and negating the shutdown bit, which defaults to “shutdown enabled.” After an hour or so of puzzling, I managed to get it displaying characters while hooked up to my usual Arduino<\/a> test harness thing.<\/p>\n

\"Lower<\/a><\/p>\n

While I was assembling the board, I realized I wasn’t sure what the proper orientation of the LED device should be. I looked for markings to indicate pin 1 and found nothing definitive. I looked at the product data sheet and they had an arrow pointing at pin 1 but nothing that clearly told me how to determine which of the pins was the first. Now, the holes I put in for the LED device in Eagle were a bit snug \u00e2\u20ac\u201d too snug, really. It required a bit of jiggering to get the LED device to fit. (I went back and made the holes slightly bigger in the design.) But, I realized this could be an advantage given my current pin alignment peril \u00e2\u20ac\u201d\u00c2 the snugness would allow the LED device’s pins to make contact with the through-holes’ platings! In other words, I could fit the device one way and not solder the pins to see if I had the thing right-way-around.<\/p>\n

\"Evil<\/a><\/p>\n

Well, that worked. A consequence of it working was that some of the columns and rows didn’t illuminate quite consistently \u00e2\u20ac\u201d\u00c2 they’d flicker and such \u00e2\u20ac\u201d and a mysterious character appeared \u00e2\u20ac\u201d\u00c2 an evil rabbit was the first thing I saw.<\/p>\n

I ran through a few code gyrations and got characters to show, right-way-around, so I went ahead and soldered the LED device permanently to the board, easy-peasy.<\/p>\n

Thinking of a few possible ways to make this learning project fun to share for the show-and-tell session of the weekly luncheon I have with some friends, I decided that I’d make a combination Magic 8 Ball<\/a> \/ Cylon Detector<\/a>, the idea being that one could reasonably ask the Magic 8 Ball if one were a Cylon \u00e2\u20ac\u201d\u00c2 I mean..why not? \u00e2\u20ac\u201d which would be a lot easier than what Baltar<\/a> was trying to construct, and wouldn’t require blood samples or anything. You could just ask yourself, in the privacy of your own home or a public restroom, and then choose whether or not you wanted to share your result.<\/p>\n

So, I hooked it up to an accelerometer that detects the normative shaking motion one inflicts on the Magic 8 Ball..the evil rabbit then divines the response.<\/p>\n

Anyway, it definitely works.<\/p>\n

The Ersatz Cylon Detector is meant for entertainment purposes only. It does not purport to factually report whether or not individuals are Cylons, except for Don Milvio. (He’s definitely a weird hybrid Franco-Italian Cylon thing.) The results are for home amusement and cannot be used for discovery or detection of actual Cylons, their friends or family. The results cannot be used for legal purposes, nor as a sanction for physical violence. The Ersatz Cylon Detector and its results are not endorsed by the producers of Battlestar Galactica, The SciFi Channel, or its affiliates and their station managers.<\/span><\/p>\n


\n

Arduino Code<\/em><\/strong><\/p>\n

#include <Wire.h><\/font><\/strong><\/font>
\n#include <math.h><\/font><\/strong><\/font><\/p>\n

\/\/ http<\/font>:<\/font>\/\/wiring<\/font>.org<\/font>.co<\/font>\/reference<\/font>\/libraries<\/font>\/Wire<\/font>\/index<\/font>.html<\/font>
\n\/\/ On<\/font> the<\/font> Arduino<\/font> board<\/font>, Analog<\/font> In<\/font> 4<\/font> is<\/font> SDA<\/font>, Analog<\/font> In<\/font> 5<\/font> is<\/font> SCL<\/font>
\n\/\/ These<\/font> correspond<\/font> to<\/font> pin<\/font> 27<\/font> (<\/font>PC4<\/font>\/ADC4<\/font>\/SDA<\/font>)<\/font> and<\/font> pin<\/font> 28<\/font> (<\/font>PC5<\/font>\/ADC5<\/font>\/SCL<\/font>)<\/font> on<\/font> the<\/font> Atmega8<\/font>
\n\/\/ The<\/font> Wire<\/font> class<\/font> handles<\/font> the<\/font> TWI<\/font> transactions<\/font>, abstracting<\/font> the<\/font> nitty<\/font>–<\/font>gritty<\/font> to<\/font> make<\/font>
\n\/\/ prototyping<\/font> easy<\/font>.
\n\/\/ This<\/font> sketch<\/font> has<\/font> two<\/font> TWI<\/font> devices<\/font> connected<\/font> to<\/font> it<\/font> \u00e2\u20ac\u201d a<\/font> LIS3LV02DQ<\/font> tri<\/font>–<\/font>axis<\/font> accelerometer<\/font>
\n\/\/ and<\/font> the<\/font> MAX6953<\/font> 5x7<\/font> matrix<\/font> LED<\/font> driver<\/font>. The<\/font> MAX6953<\/font> is<\/font> at<\/font> address<\/font> 0x50<\/font>, and<\/font> the<\/font> LIS3LV02DQ<\/font> is<\/font>
\n\/\/ at<\/font> address<\/font> 0x1D<\/font>.<\/p>\n

char<\/strong> mAnswer_1<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘S’<\/font>,‘i’<\/font>,‘g’<\/font>,‘n’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘p’<\/font>,‘o’<\/font>,‘i’<\/font>,‘n’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘t’<\/font>,‘o’<\/font>,‘ ‘<\/font>,‘y’<\/font>,‘e’<\/font>,‘s’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_2<\/font>[<\/font>4<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘Y’<\/font>,‘e’<\/font>,‘s’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_3<\/font>[<\/font>12<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘M’<\/font>,‘o’<\/font>,‘s’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘l’<\/font>,‘i’<\/font>,‘k’<\/font>,‘e’<\/font>,‘l’<\/font>,‘y’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_4<\/font>[<\/font>16<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘W’<\/font>,‘i’<\/font>,‘t’<\/font>,‘h’<\/font>,‘o’<\/font>,‘u’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘o’<\/font>,‘u’<\/font>,‘b’<\/font>,‘t’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_5<\/font>{<\/strong><\/font>16<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘Y’<\/font>,‘e’<\/font>,‘s’<\/font>,‘,’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘e’<\/font>,‘f’<\/font>,‘i’<\/font>,‘n’<\/font>,‘i’<\/font>,‘t’<\/font>,‘e’<\/font>,‘l’<\/font>,‘y’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_6<\/font>[<\/font>17<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘A’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘I’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘e’<\/font>,‘e’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘t’<\/font>,‘,’<\/font>,‘ ‘<\/font>,‘y’<\/font>,‘e’<\/font>,‘s’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_7<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘Y’<\/font>,‘o’<\/font>,‘u’<\/font>,‘ ‘<\/font>,‘m’<\/font>,‘a’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘r’<\/font>,‘e’<\/font>,‘l’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘o’<\/font>,‘n’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘t’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_8<\/font>[<\/font>13<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘O’<\/font>,‘u’<\/font>,‘t’<\/font>,‘l’<\/font>,‘o’<\/font>,‘o’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘g’<\/font>,‘o’<\/font>,‘o’<\/font>,‘d’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_9<\/font>[<\/font>14<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘I’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘c’<\/font>,‘e’<\/font>,‘r’<\/font>,‘t’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_10<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘I’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘e’<\/font>,‘c’<\/font>,‘i’<\/font>,‘d’<\/font>,‘e’<\/font>,‘d’<\/font>,‘l’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘o’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_11<\/font>[<\/font>22<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘R’<\/font>,‘e’<\/font>,‘p’<\/font>,‘l’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘h’<\/font>,‘a’<\/font>,‘z’<\/font>,‘y’<\/font>,‘,’<\/font>,‘ ‘<\/font>,‘t’<\/font>,‘r’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘g’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_12<\/font>[<\/font>24<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘B’<\/font>,‘e’<\/font>,‘t’<\/font>,‘t’<\/font>,‘e’<\/font>,‘r’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘t’<\/font>,‘e’<\/font>,‘l’<\/font>,‘l’<\/font>,‘ ‘<\/font>,‘y’<\/font>,‘o’<\/font>,‘u’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘w’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_13<\/font>[<\/font>16<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘A’<\/font>,‘s’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘g’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,‘ ‘<\/font>,‘l’<\/font>,‘a’<\/font>,‘t’<\/font>,‘e’<\/font>,‘r’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_14<\/font>[<\/font>26<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘C’<\/font>,‘o’<\/font>,‘n’<\/font>,‘c’<\/font>,‘e’<\/font>,‘n’<\/font>,‘t’<\/font>,‘r’<\/font>,‘a’<\/font>,‘t’<\/font>,‘e’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘n’<\/font>,‘d’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘s’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘g’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_15<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘C’<\/font>,‘a’<\/font>,‘n’<\/font>,‘n’<\/font>,‘o’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘p’<\/font>,‘r’<\/font>,‘e’<\/font>,‘d’<\/font>,‘i’<\/font>,‘c’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘w’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_16<\/font>[<\/font>18<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘M’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘o’<\/font>,‘u’<\/font>,‘r’<\/font>,‘c’<\/font>,‘e’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘a’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_17<\/font>[<\/font>14<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘V’<\/font>,‘e’<\/font>,‘r’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘o’<\/font>,‘u’<\/font>,‘b’<\/font>,‘t’<\/font>,‘f’<\/font>,‘u’<\/font>,‘l’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_18<\/font>[<\/font>20<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘O’<\/font>,‘u’<\/font>,‘t’<\/font>,‘l’<\/font>,‘o’<\/font>,‘o’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘o’<\/font>,‘ ‘<\/font>,‘g’<\/font>,‘o’<\/font>,‘o’<\/font>,‘d’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_19<\/font>[<\/font>18<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘D’<\/font>,‘o’<\/font>,‘n’<\/font>,‘<\/font>‘<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘c’<\/font>,‘o’<\/font>,‘u’<\/font>,‘n’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘o’<\/font>,‘n’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘t’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font><\/p>\n

void<\/strong> setup<\/font>(<\/font>)<\/font>
\n{<\/strong><\/font><\/p>\n

Serial<\/font>.begin<\/font>(<\/font>9600<\/font>)<\/font>;<\/font><\/p>\n

CLKPR<\/font> =<\/font> (<\/font>1<\/font><<\/font><<\/font>CLKPCE<\/font>)<\/font>;<\/font>
\n CLKPR<\/font> =<\/font> 0<\/font>;<\/font><\/p>\n

\/\/ initialize<\/font> the<\/font> LIS3LV02DQ<\/font>
\n Wire<\/font>.begin<\/font>(<\/font>)<\/font>;<\/font> \/\/ join<\/font> i2c<\/font> bus<\/font> (<\/font>address<\/font> optional<\/font> for<\/strong> master<\/font>)<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x20<\/font>)<\/font>;<\/font> \/\/ CTRL_REG1<\/font> (<\/font>20h<\/font>)<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x87<\/font>)<\/font>;<\/font> \/\/ Device<\/font> on<\/font>, 40hz<\/font>, normal<\/font> mode<\/font>, all<\/font> axis<\/font>‘s<\/font> enabled<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

\/\/ initialize<\/font> the<\/font> MAX6953<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x07<\/font>)<\/font>;<\/font> \/\/ Display<\/font> Test<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x00<\/font>)<\/font>;<\/font> \/\/ Normal<\/font> Operation<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ Intensity16<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x0F<\/font>)<\/font>;<\/font> \/\/ Full<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x04<\/font>)<\/font>;<\/font> \/\/ configuration<\/font> register<\/strong>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ disable<\/font> shutdown<\/font> mode<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n initializeSpecialCharacters<\/font>(<\/font>)<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

void<\/strong> loop<\/font>(<\/font>)<\/font> {<\/strong><\/font>
\n int<\/strong> z_val<\/font>, x_val<\/font>, y_val<\/font>;<\/font>
\n int<\/strong> sum_sq<\/font>, sum_sq_2<\/font>, diff<\/font>, mShake<\/font>, message<\/font>;<\/font>
\n int<\/strong> max_accel<\/font>;<\/font>
\n byte<\/font> i<\/font>;<\/font><\/p>\n

message<\/font> =<\/font> 0<\/font>;<\/font><\/p>\n

setCharacter<\/font>(<\/font>0x00<\/font>)<\/font>;<\/font>
\n delay<\/font>(<\/font>random<\/font>(<\/font>500<\/font>,1000<\/font>)<\/font>)<\/font>;<\/font>
\n setCharacter<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font>
\n delay<\/font>(<\/font>random<\/font>(<\/font>500<\/font>,1500<\/font>)<\/font>)<\/font>;<\/font><\/p>\n

x_val<\/font> =<\/font> getX<\/font>(<\/font>)<\/font>;<\/font>
\n y_val<\/font> =<\/font> getY<\/font>(<\/font>)<\/font>;<\/font>
\n z_val<\/font> =<\/font> getZ<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

sum_sq<\/font> =<\/font> sqrt<\/font>(<\/font>pow<\/font>(<\/font>x_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>y_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>z_val<\/font>, 2<\/font>)<\/font>)<\/font>;<\/font><\/p>\n

delay<\/font>(<\/font>100<\/font>)<\/font>;<\/font>
\n x_val<\/font> =<\/font> getX<\/font>(<\/font>)<\/font>;<\/font>
\n y_val<\/font> =<\/font> getY<\/font>(<\/font>)<\/font>;<\/font>
\n z_val<\/font> =<\/font> getZ<\/font>(<\/font>)<\/font>;<\/font>
\nmShake<\/font> =<\/font> 0<\/font>;<\/font>
\nsum_sq_2<\/font> =<\/font> sqrt<\/font>(<\/font>pow<\/font>(<\/font>x_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>y_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>z_val<\/font>, 2<\/font>)<\/font>)<\/font>;<\/font>
\ndiff<\/font> =<\/font> abs<\/font>(<\/font>sum_sq<\/font>–<\/font>sum_sq_2<\/font>)<\/font>;<\/font>
\nif<\/strong>(<\/font>diff<\/font> ><\/font> 300<\/font>)<\/font> {<\/strong><\/font> mShake<\/font> =<\/font> 1<\/font>;<\/font> }<\/strong><\/font>
\nif<\/strong>(<\/font>diff<\/font> ><\/font> 1000<\/font>)<\/font> {<\/strong><\/font> mShake<\/font> =<\/font> 2<\/font>;<\/font> }<\/strong><\/font>
\nif<\/strong>(<\/font>diff<\/font> ><\/font> 1200<\/font>)<\/font> {<\/strong><\/font> mShake<\/font> =<\/font> 3<\/font>;<\/font> }<\/strong><\/font><\/p>\n

\/\/Serial<\/font>.print<\/font>(<\/font>diff<\/font>)<\/font>;<\/font> Serial<\/font>.print<\/font>(<\/font>" "<\/font>)<\/font>;<\/font> Serial<\/font>.print<\/font>(<\/font>max_accel<\/font>)<\/font>;<\/font> Serial<\/font>.print<\/font>(<\/font>" "<\/font>)<\/font>;<\/font> Serial<\/font>.println<\/font>(<\/font>mShake<\/font>)<\/font>;<\/font><\/p>\n

if<\/strong>(<\/font>diff<\/font> ><\/font> max_accel<\/font>)<\/font> max_accel<\/font> =<\/font> diff<\/font>;<\/font><\/p>\n

\/\/delay<\/font>(<\/font>500<\/font>)<\/font>;<\/font><\/p>\n

if<\/strong>(<\/font>mShake<\/font> ><\/font> 0<\/font>)<\/font> {<\/strong><\/font>
\n\tmessage<\/font> =<\/font> random<\/font>(<\/font>0<\/font>,18<\/font>)<\/font>;<\/font>
\n\tfor<\/strong>(<\/font>int<\/strong> i<\/font>=<\/font>0<\/font>;<\/font> i<\/font><<\/font>3<\/font>;<\/font> i<\/font>+<\/font>+<\/font>)<\/font> {<\/strong><\/font>
\n\t\tsetCharacter<\/font>(<\/font>‘*’<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>500<\/font>)<\/font>;<\/font> setCharacter<\/font>(<\/font>‘ ‘<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>500<\/font>)<\/font>;<\/font>
\n\t}<\/strong><\/font>
\n }<\/strong><\/font> else<\/strong> {<\/strong><\/font>
\n message<\/font> =<\/font> –<\/font>1<\/font>;<\/font>
\n }<\/strong><\/font>
\n\tswitch<\/strong>(<\/font>message<\/font>)<\/font> {<\/strong><\/font>
\n\t case<\/strong> 0<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_1<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_1<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n\t break<\/strong>;<\/font>
\n\t case<\/strong> 1<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_2<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_2<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n\t case<\/strong> 2<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_3<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_3<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n\t break<\/strong>;<\/font>
\n\t case<\/strong> 3<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_4<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_4<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 4<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 5<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 6<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_6<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_6<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 7<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_7<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_7<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 8<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_8<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_8<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 9<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_9<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_9<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 10<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_10<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_10<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 11<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_11<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_11<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 12<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_12<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_12<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 13<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_13<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_13<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 14<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_14<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_14<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 15<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_15<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_15<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 16<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_16<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_16<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 17<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_17<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_17<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 18<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_18<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_18<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 19<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_19<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_19<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t default<\/strong>:<\/font>
\n break<\/strong>;<\/font>
\n\t}<\/strong><\/font>
\n\tmessage<\/font> =<\/font> 0<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

void<\/strong> flickerOutIntensity<\/font>(<\/font>)<\/font>
\n{<\/strong><\/font>
\n for<\/strong>(<\/font>int<\/strong> i<\/font>=<\/font>16<\/font>;<\/font> i<\/font>><\/font>=<\/font>0<\/font>;<\/font> i<\/font>–<\/font>–<\/font>)<\/font> {<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ Intensity16<\/font>
\n Wire<\/font>.send<\/font>(<\/font>i<\/font>)<\/font>;<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n delay<\/font>(<\/font>random<\/font>(<\/font>400<\/font>)<\/font>)<\/font>;<\/font>
\n if<\/strong>(<\/font>i<\/font> %<\/font> 4<\/font> =<\/font>=<\/font> 0<\/font>)<\/font> {<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ Intensity16<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x02<\/font>)<\/font>;<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n delay<\/font>(<\/font>random<\/font>(<\/font>500<\/font>)<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font>
\n }<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ Intensity16<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x0f<\/font>)<\/font>;<\/font> \/\/ Full<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

\/\/ create<\/font> two<\/font> custom<\/font> characters<\/font> that<\/font> look<\/font> like<\/font> an<\/font> evil<\/font> cylon<\/font> detecting<\/font> magic<\/font> 8<\/font> ball<\/font> rabbit<\/font>
\n\/\/ this<\/font> writes<\/font> the<\/font> two<\/font> characters<\/font> by<\/font> writing<\/font> first<\/font> to<\/font> register<\/strong> 0x05<\/font> the<\/font> value<\/font> 0x80<\/font>, which<\/font> is<\/font>
\n\/\/ the<\/font> address<\/font> of<\/font> the<\/font> first<\/font> 7<\/font> bits<\/font> of<\/font> he<\/font> first<\/font> user<\/font>–<\/font>created<\/font> font<\/font> character<\/font>. Each<\/font> character<\/font>
\n\/\/ has<\/font> 5<\/font> rows<\/font> of<\/font> 7<\/font> bits<\/font>, you<\/font> write<\/font> to<\/font> each<\/font> row<\/font> in<\/font> sequence<\/font>. The<\/font> MAX6953<\/font> will<\/font> autoincrement<\/font>
\n\/\/ the<\/font> address<\/font> written<\/font> during<\/font> the<\/font> I2C<\/font>\/TWI<\/font> transaction<\/font>, so<\/font> each<\/font> of<\/font> these<\/font> Wire<\/font>.send<\/font> instructions<\/font>
\n\/\/ is<\/font> writing<\/font> to<\/font> the<\/font> next<\/font> row<\/font>.
\nvoid<\/strong> initializeSpecialCharacters<\/font>
\n{<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x05<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x80<\/font>)<\/font>;<\/font><\/p>\n

\/\/ character<\/font> 0x00<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x7f<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x14<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x44<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x14<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x7f<\/font>)<\/font>;<\/font><\/p>\n

\/\/ character<\/font> 0x01<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x7f<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x04<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x44<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x04<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x7f<\/font>)<\/font>;<\/font><\/p>\n

Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

}<\/strong><\/font><\/p>\n

void<\/strong> setCharacter<\/font>(<\/font>char<\/strong> c<\/font>)<\/font>
\n{<\/strong><\/font>
\n\/\/ if<\/strong>(<\/font>c<\/font> ><\/font>=<\/font> 0x20<\/font> &<\/font>&<\/font> c<\/font> <<\/font>=<\/font> 0x7F<\/font>)<\/font> {<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x20<\/font>)<\/font>;<\/font> \/\/ Digit<\/font> 0<\/font> Plane<\/font> 0<\/font>
\n Wire<\/font>.send<\/font>(<\/font>c<\/font>)<\/font>;<\/font> \/\/ N<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n\/\/ }<\/strong><\/font>
\n}<\/strong><\/font><\/p>\n

int<\/strong> getX<\/font>(<\/font>)<\/font>
\n{<\/strong><\/font>
\n byte<\/font> x_val_l<\/font>, x_val_h<\/font>;<\/font>
\n int<\/strong> x_val<\/font>, y_val<\/font>;<\/font>
\n \/\/Serial<\/font>.println<\/font>(<\/font>"hello?"<\/font>)<\/font>;<\/font>
\n \/\/byte<\/font> in_byte<\/font>;<\/font>
\n \/\/ transmit<\/font> to<\/font> device<\/font> with<\/font> address<\/font> 0x1D<\/font>
\n \/\/ according<\/font> to<\/font> the<\/font> LIS3L<\/font>*<\/font> datasheet<\/font>, the<\/font> i2c<\/font> address<\/font> of<\/font> is<\/font> fixed<\/font>
\n \/\/ at<\/font> the<\/font> factory<\/font> at<\/font> 0011101b<\/font> (<\/font>0x1D<\/font>)<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font>
\n \/\/ send<\/font> the<\/font> sub<\/font> address<\/font> for<\/strong> the<\/font> register<\/strong> we<\/font> want<\/font> to<\/font> read<\/font>
\n \/\/ this<\/font> is<\/font> for<\/strong> the<\/font> OUTZ_H<\/font> register<\/strong>
\n \/\/ n<\/font>.b<\/font>. supposedly<\/font> masking<\/font> the<\/font> register<\/strong> address<\/font> with<\/font> 0x80<\/font>,
\n \/\/ you<\/font> can<\/font> do<\/strong> multiple<\/font> reads<\/font>, with<\/font> the<\/font> register<\/strong> address<\/font> auto<\/strong>–<\/font>incremented<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x28<\/font>)<\/font>;<\/font>
\n \/\/ stop<\/font> transmitting<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n \/\/ Now<\/font> do<\/strong> a<\/font> transfer<\/font> reading<\/font> one<\/font> byte<\/font> from<\/font> the<\/font> LIS3L<\/font>*<\/font>
\n \/\/ This<\/font> data<\/font> will<\/font> be<\/font> the<\/font> contents<\/font> of<\/font> register<\/strong> 0x28<\/font>
\n Wire<\/font>.requestFrom<\/font>(<\/font>0x1D<\/font>, 1<\/font>)<\/font>;<\/font>
\n while<\/strong>(<\/font>Wire<\/font>.available<\/font>(<\/font>)<\/font>)<\/font>
\n {<\/strong><\/font>
\n x_val_l<\/font> =<\/font> Wire<\/font>.receive<\/font>(<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font> Wire<\/font>.send<\/font>(<\/font>0x29<\/font>)<\/font>;<\/font> Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n Wire<\/font>.requestFrom<\/font>(<\/font>0x1D<\/font>, 1<\/font>)<\/font>;<\/font>
\n while<\/strong>(<\/font>Wire<\/font>.available<\/font>(<\/font>)<\/font>)<\/font>
\n {<\/strong><\/font>
\n x_val_h<\/font> =<\/font> Wire<\/font>.receive<\/font>(<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font>
\n x_val<\/font> =<\/font> x_val_h<\/font>;<\/font>
\n x_val<\/font> <<\/font><<\/font>=<\/font> 8<\/font>;<\/font>
\n x_val<\/font> +<\/font>=<\/font> x_val_l<\/font>;<\/font><\/p>\n

return<\/strong> x_val<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

int<\/strong> getY<\/font>(<\/font>)<\/font>
\n{<\/strong><\/font>
\n byte<\/font> y_val_l<\/font>, y_val_h<\/font>;<\/font>
\n int<\/strong> y_val<\/font>;<\/font>
\n \/\/ Y<\/font> Axis<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font> Wire<\/font>.send<\/font>(<\/font>0x2A<\/font>)<\/font>;<\/font> Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n Wire<\/font>.requestFrom<\/font>(<\/font>0x1D<\/font>, 1<\/font>)<\/font>;<\/font>
\n while<\/strong>(<\/font>Wire<\/font>.available<\/font>(<\/font>)<\/font>)<\/font>
\n {<\/strong><\/font>
\n y_val_l<\/font> =<\/font> Wire<\/font>.receive<\/font>(<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font> Wire<\/font>.send<\/font>(<\/font>0x2B<\/font>)<\/font>;<\/font> Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n Wire<\/font>.requestFrom<\/font>(<\/font>0x1D<\/font>, 1<\/font>)<\/font>;<\/font>
\n while<\/strong>(<\/font>Wire<\/font>.available<\/font>(<\/font>)<\/font>)<\/font>
\n {<\/strong><\/font>
\n y_val_h<\/font> =<\/font> Wire<\/font>.receive<\/font>(<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font><\/p>\n

y_val<\/font> =<\/font> y_val_h<\/font>;<\/font>
\n y_val<\/font> <<\/font><<\/font>=<\/font> 8<\/font>;<\/font>
\n y_val<\/font> +<\/font>=<\/font> y_val_l<\/font>;<\/font><\/p>\n

return<\/strong> y_val<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

int<\/strong> getZ<\/font>(<\/font>)<\/font>
\n{<\/strong><\/font>
\n byte<\/font> z_val_l<\/font>, z_val_h<\/font>;<\/font>
\n int<\/strong> z_val<\/font>;<\/font>
\n \/\/ Z<\/font> Axis<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font> Wire<\/font>.send<\/font>(<\/font>0x2C<\/font>)<\/font>;<\/font> Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n Wire<\/font>.requestFrom<\/font>(<\/font>0x1D<\/font>, 1<\/font>)<\/font>;<\/font>
\n while<\/strong>(<\/font>Wire<\/font>.available<\/font>(<\/font>)<\/font>)<\/font>
\n {<\/strong><\/font>
\n z_val_l<\/font> =<\/font> Wire<\/font>.receive<\/font>(<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font> Wire<\/font>.send<\/font>(<\/font>0x2D<\/font>)<\/font>;<\/font> Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n Wire<\/font>.requestFrom<\/font>(<\/font>0x1D<\/font>, 1<\/font>)<\/font>;<\/font>
\n while<\/strong>(<\/font>Wire<\/font>.available<\/font>(<\/font>)<\/font>)<\/font>
\n {<\/strong><\/font>
\n z_val_h<\/font> =<\/font> Wire<\/font>.receive<\/font>(<\/font>)<\/font>;<\/font>
\n }<\/strong><\/font><\/p>\n

z_val<\/font> =<\/font> z_val_h<\/font>;<\/font>
\n z_val<\/font> <<\/font><<\/font>=<\/font> 8<\/font>;<\/font>
\n z_val<\/font> +<\/font>=<\/font> z_val_l<\/font>;<\/font><\/p>\n

return<\/strong> z_val<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

Update \u2014 here are a schematic and a board layout for the little board in the picture that contains the MAX6953 and the Matrix LED. I used my own breakout board like this, rather than run a whole bunch of wires from the 6953 to the Matrix LED.<\/em><\/strong><\/p>\n

\n\"SlowMail_Schematic\"<\/a>\n<\/div>\n

<\/p>\n

\n\"SlowMail_Board\"<\/a>\n<\/div>\n

\n
\n\"Creative<\/a>
\n
This work<\/span> is licensed under a
Creative Commons Attribution-ShareAlike 3.0 License<\/a>.<\/p>\n

<\/p>\n

Technorati Tags: Arduino<\/a>, Cylon Detector<\/a><\/p>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"

\"Cylon<\/a><\/p>\n

An on-going project that requires the display of alphabetic and numeric characters using a 5×7 LED matrix turned me towards a chip by Maxim IC<\/a> \u00e2\u20ac\u201d the MAX6953<\/a>. The chip, while expensive (~$8), has lots of built-in features that mitigate the damage to my purse, trading such in kind for time-saved. It will directly drive up to 4 5×7 LED matrices<\/a> with direct control from a microcontroller over a two-wire interface (TWI\/I2C)<\/a>, can manage varying intensities (16 or 32 degree scales), has a built-in Arial-like font set with a reasonably full-range of characters, diacritics and symbols, and allows me to create 24 characters of my own design.<\/p>\n

\"SlowMessenger_Max6953_Breakout\"<\/a><\/p>\n

\n

\"SlowMessenger_Max6953_Breakout_Board\"<\/a><\/p>\n

\n

My first attempt at mucking with the chip used the DIP version, which is ginormous and requires such patience and diligence with wiring the thing up \u00e2\u20ac\u201d\u00c2 all those lines going to the pins of the LED matrix \u00e2\u20ac\u201d that I pretty much gave up after it didn’t work the first time. I decided that I’d just go ahead and design a PCB for the thing and continue to hone my skills with Eagle<\/a>, while also learning how to work with the MAX6953.<\/p>\n

\"\"<\/a><\/p>\n

\"\"<\/a><\/p>\n

\"\"<\/a><\/p>\n

\"Some<\/a><\/p>\n

I sent a design off<\/a>, it came back, I stared at it for a few minutes, looked for the MAX6953’s in my bin of samples and realized I didn’t have any. I managed to coax a bunch from Maxim’s sample guy, which is great. (Thanks whoever you are, wherever you are.) A couple of weeks later, when my plate was relatively clear, I assembled one of the boards, using a yellowish\/orange 5×7 matrix LED<\/a> I purchased from Digikey<\/a> and manufactured by LiteOn<\/a>. I wanted small, but the closest I got to small was 0.7″, which still seems big to me. (The story of it’s assembly<\/a> and problems therein is instructive if you’re curious about surface-mount PCB work..and the problems therein.)<\/p>\n

I powered the thing up and, naturally enough, it didn’t illuminate at all. I poked through the spec sheet and figured out that there’s a whole start-up ritual you’ll want to go through, such as the test mode and negating the shutdown bit, which defaults to “shutdown enabled.” After an hour or so of puzzling, I managed to get it displaying characters while hooked up to my usual Arduino<\/a> test harness thing.<\/p>\n

\"Lower<\/a><\/p>\n

While I was assembling the board, I realized I wasn’t sure what the proper orientation of the LED device should be. I looked for markings to indicate pin 1 and found nothing definitive. I looked at the product data sheet and they had an arrow pointing at pin 1 but nothing that clearly told me how to determine which of the pins was the first. Now, the holes I put in for the LED device in Eagle were a bit snug \u00e2\u20ac\u201d too snug, really. It required a bit of jiggering to get the LED device to fit. (I went back and made the holes slightly bigger in the design.) But, I realized this could be an advantage given my current pin alignment peril \u00e2\u20ac\u201d\u00c2 the snugness would allow the LED device’s pins to make contact with the through-holes’ platings! In other words, I could fit the device one way and not solder the pins to see if I had the thing right-way-around.<\/p>\n

\"Evil<\/a><\/p>\n

Well, that worked. A consequence of it working was that some of the columns and rows didn’t illuminate quite consistently \u00e2\u20ac\u201d\u00c2 they’d flicker and such \u00e2\u20ac\u201d and a mysterious character appeared \u00e2\u20ac\u201d\u00c2 an evil rabbit was the first thing I saw.<\/p>\n

I ran through a few code gyrations and got characters to show, right-way-around, so I went ahead and soldered the LED device permanently to the board, easy-peasy.<\/p>\n

Thinking of a few possible ways to make this learning project fun to share for the show-and-tell session of the weekly luncheon I have with some friends, I decided that I’d make a combination Magic 8 Ball<\/a> \/ Cylon Detector<\/a>, the idea being that one could reasonably ask the Magic 8 Ball if one were a Cylon \u00e2\u20ac\u201d\u00c2 I mean..why not? \u00e2\u20ac\u201d which would be a lot easier than what Baltar<\/a> was trying to construct, and wouldn’t require blood samples or anything. You could just ask yourself, in the privacy of your own home or a public restroom, and then choose whether or not you wanted to share your result.<\/p>\n

So, I hooked it up to an accelerometer that detects the normative shaking motion one inflicts on the Magic 8 Ball..the evil rabbit then divines the response.<\/p>\n

Anyway, it definitely works.<\/p>\n

The Ersatz Cylon Detector is meant for entertainment purposes only. It does not purport to factually report whether or not individuals are Cylons, except for Don Milvio. (He’s definitely a weird hybrid Franco-Italian Cylon thing.) The results are for home amusement and cannot be used for discovery or detection of actual Cylons, their friends or family. The results cannot be used for legal purposes, nor as a sanction for physical violence. The Ersatz Cylon Detector and its results are not endorsed by the producers of Battlestar Galactica, The SciFi Channel, or its affiliates and their station managers.<\/span><\/p>\n


\n

Arduino Code<\/em><\/strong><\/p>\n

#include <Wire.h><\/font><\/strong><\/font>
\n#include <math.h><\/font><\/strong><\/font><\/p>\n

\/\/ http<\/font>:<\/font>\/\/wiring<\/font>.org<\/font>.co<\/font>\/reference<\/font>\/libraries<\/font>\/Wire<\/font>\/index<\/font>.html<\/font>
\n\/\/ On<\/font> the<\/font> Arduino<\/font> board<\/font>, Analog<\/font> In<\/font> 4<\/font> is<\/font> SDA<\/font>, Analog<\/font> In<\/font> 5<\/font> is<\/font> SCL<\/font>
\n\/\/ These<\/font> correspond<\/font> to<\/font> pin<\/font> 27<\/font> (<\/font>PC4<\/font>\/ADC4<\/font>\/SDA<\/font>)<\/font> and<\/font> pin<\/font> 28<\/font> (<\/font>PC5<\/font>\/ADC5<\/font>\/SCL<\/font>)<\/font> on<\/font> the<\/font> Atmega8<\/font>
\n\/\/ The<\/font> Wire<\/font> class<\/font> handles<\/font> the<\/font> TWI<\/font> transactions<\/font>, abstracting<\/font> the<\/font> nitty<\/font>–<\/font>gritty<\/font> to<\/font> make<\/font>
\n\/\/ prototyping<\/font> easy<\/font>.
\n\/\/ This<\/font> sketch<\/font> has<\/font> two<\/font> TWI<\/font> devices<\/font> connected<\/font> to<\/font> it<\/font> \u00e2\u20ac\u201d a<\/font> LIS3LV02DQ<\/font> tri<\/font>–<\/font>axis<\/font> accelerometer<\/font>
\n\/\/ and<\/font> the<\/font> MAX6953<\/font> 5x7<\/font> matrix<\/font> LED<\/font> driver<\/font>. The<\/font> MAX6953<\/font> is<\/font> at<\/font> address<\/font> 0x50<\/font>, and<\/font> the<\/font> LIS3LV02DQ<\/font> is<\/font>
\n\/\/ at<\/font> address<\/font> 0x1D<\/font>.<\/p>\n

char<\/strong> mAnswer_1<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘S’<\/font>,‘i’<\/font>,‘g’<\/font>,‘n’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘p’<\/font>,‘o’<\/font>,‘i’<\/font>,‘n’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘t’<\/font>,‘o’<\/font>,‘ ‘<\/font>,‘y’<\/font>,‘e’<\/font>,‘s’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_2<\/font>[<\/font>4<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘Y’<\/font>,‘e’<\/font>,‘s’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_3<\/font>[<\/font>12<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘M’<\/font>,‘o’<\/font>,‘s’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘l’<\/font>,‘i’<\/font>,‘k’<\/font>,‘e’<\/font>,‘l’<\/font>,‘y’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_4<\/font>[<\/font>16<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘W’<\/font>,‘i’<\/font>,‘t’<\/font>,‘h’<\/font>,‘o’<\/font>,‘u’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘o’<\/font>,‘u’<\/font>,‘b’<\/font>,‘t’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_5<\/font>{<\/strong><\/font>16<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘Y’<\/font>,‘e’<\/font>,‘s’<\/font>,‘,’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘e’<\/font>,‘f’<\/font>,‘i’<\/font>,‘n’<\/font>,‘i’<\/font>,‘t’<\/font>,‘e’<\/font>,‘l’<\/font>,‘y’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_6<\/font>[<\/font>17<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘A’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘I’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘e’<\/font>,‘e’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘t’<\/font>,‘,’<\/font>,‘ ‘<\/font>,‘y’<\/font>,‘e’<\/font>,‘s’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_7<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘Y’<\/font>,‘o’<\/font>,‘u’<\/font>,‘ ‘<\/font>,‘m’<\/font>,‘a’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘r’<\/font>,‘e’<\/font>,‘l’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘o’<\/font>,‘n’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘t’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_8<\/font>[<\/font>13<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘O’<\/font>,‘u’<\/font>,‘t’<\/font>,‘l’<\/font>,‘o’<\/font>,‘o’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘g’<\/font>,‘o’<\/font>,‘o’<\/font>,‘d’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_9<\/font>[<\/font>14<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘I’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘c’<\/font>,‘e’<\/font>,‘r’<\/font>,‘t’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_10<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘I’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘e’<\/font>,‘c’<\/font>,‘i’<\/font>,‘d’<\/font>,‘e’<\/font>,‘d’<\/font>,‘l’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘o’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_11<\/font>[<\/font>22<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘R’<\/font>,‘e’<\/font>,‘p’<\/font>,‘l’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘h’<\/font>,‘a’<\/font>,‘z’<\/font>,‘y’<\/font>,‘,’<\/font>,‘ ‘<\/font>,‘t’<\/font>,‘r’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘g’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_12<\/font>[<\/font>24<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘B’<\/font>,‘e’<\/font>,‘t’<\/font>,‘t’<\/font>,‘e’<\/font>,‘r’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘t’<\/font>,‘e’<\/font>,‘l’<\/font>,‘l’<\/font>,‘ ‘<\/font>,‘y’<\/font>,‘o’<\/font>,‘u’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘w’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_13<\/font>[<\/font>16<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘A’<\/font>,‘s’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘g’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,‘ ‘<\/font>,‘l’<\/font>,‘a’<\/font>,‘t’<\/font>,‘e’<\/font>,‘r’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_14<\/font>[<\/font>26<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘C’<\/font>,‘o’<\/font>,‘n’<\/font>,‘c’<\/font>,‘e’<\/font>,‘n’<\/font>,‘t’<\/font>,‘r’<\/font>,‘a’<\/font>,‘t’<\/font>,‘e’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘n’<\/font>,‘d’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘s’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘a’<\/font>,‘g’<\/font>,‘a’<\/font>,‘i’<\/font>,‘n’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_15<\/font>[<\/font>19<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘C’<\/font>,‘a’<\/font>,‘n’<\/font>,‘n’<\/font>,‘o’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘p’<\/font>,‘r’<\/font>,‘e’<\/font>,‘d’<\/font>,‘i’<\/font>,‘c’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘w’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_16<\/font>[<\/font>18<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘M’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘o’<\/font>,‘u’<\/font>,‘r’<\/font>,‘c’<\/font>,‘e’<\/font>,‘s’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘a’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_17<\/font>[<\/font>14<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘V’<\/font>,‘e’<\/font>,‘r’<\/font>,‘y’<\/font>,‘ ‘<\/font>,‘d’<\/font>,‘o’<\/font>,‘u’<\/font>,‘b’<\/font>,‘t’<\/font>,‘f’<\/font>,‘u’<\/font>,‘l’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_18<\/font>[<\/font>20<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘O’<\/font>,‘u’<\/font>,‘t’<\/font>,‘l’<\/font>,‘o’<\/font>,‘o’<\/font>,‘k’<\/font>,‘ ‘<\/font>,‘n’<\/font>,‘o’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘s’<\/font>,‘o’<\/font>,‘ ‘<\/font>,‘g’<\/font>,‘o’<\/font>,‘o’<\/font>,‘d’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font>
\nchar<\/strong> mAnswer_19<\/font>[<\/font>18<\/font>]<\/font> =<\/font> {<\/strong><\/font>‘D’<\/font>,‘o’<\/font>,‘n’<\/font>,‘<\/font>‘<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘c’<\/font>,‘o’<\/font>,‘u’<\/font>,‘n’<\/font>,‘t’<\/font>,‘ ‘<\/font>,‘o’<\/font>,‘n’<\/font>,‘ ‘<\/font>,‘i’<\/font>,‘t’<\/font>,0x00<\/font>}<\/strong><\/font>;<\/font><\/p>\n

void<\/strong> setup<\/font>(<\/font>)<\/font>
\n{<\/strong><\/font><\/p>\n

Serial<\/font>.begin<\/font>(<\/font>9600<\/font>)<\/font>;<\/font><\/p>\n

CLKPR<\/font> =<\/font> (<\/font>1<\/font><<\/font><<\/font>CLKPCE<\/font>)<\/font>;<\/font>
\n CLKPR<\/font> =<\/font> 0<\/font>;<\/font><\/p>\n

\/\/ initialize<\/font> the<\/font> LIS3LV02DQ<\/font>
\n Wire<\/font>.begin<\/font>(<\/font>)<\/font>;<\/font> \/\/ join<\/font> i2c<\/font> bus<\/font> (<\/font>address<\/font> optional<\/font> for<\/strong> master<\/font>)<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x1D<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x20<\/font>)<\/font>;<\/font> \/\/ CTRL_REG1<\/font> (<\/font>20h<\/font>)<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x87<\/font>)<\/font>;<\/font> \/\/ Device<\/font> on<\/font>, 40hz<\/font>, normal<\/font> mode<\/font>, all<\/font> axis<\/font>‘s<\/font> enabled<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

\/\/ initialize<\/font> the<\/font> MAX6953<\/font>
\n Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x07<\/font>)<\/font>;<\/font> \/\/ Display<\/font> Test<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x00<\/font>)<\/font>;<\/font> \/\/ Normal<\/font> Operation<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ Intensity16<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x0F<\/font>)<\/font>;<\/font> \/\/ Full<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

Wire<\/font>.beginTransmission<\/font>(<\/font>0x50<\/font>)<\/font>;<\/font>
\n Wire<\/font>.send<\/font>(<\/font>0x04<\/font>)<\/font>;<\/font> \/\/ configuration<\/font> register<\/strong>
\n Wire<\/font>.send<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font> \/\/ disable<\/font> shutdown<\/font> mode<\/font>
\n Wire<\/font>.endTransmission<\/font>(<\/font>)<\/font>;<\/font>
\n initializeSpecialCharacters<\/font>(<\/font>)<\/font>;<\/font>
\n}<\/strong><\/font><\/p>\n

void<\/strong> loop<\/font>(<\/font>)<\/font> {<\/strong><\/font>
\n int<\/strong> z_val<\/font>, x_val<\/font>, y_val<\/font>;<\/font>
\n int<\/strong> sum_sq<\/font>, sum_sq_2<\/font>, diff<\/font>, mShake<\/font>, message<\/font>;<\/font>
\n int<\/strong> max_accel<\/font>;<\/font>
\n byte<\/font> i<\/font>;<\/font><\/p>\n

message<\/font> =<\/font> 0<\/font>;<\/font><\/p>\n

setCharacter<\/font>(<\/font>0x00<\/font>)<\/font>;<\/font>
\n delay<\/font>(<\/font>random<\/font>(<\/font>500<\/font>,1000<\/font>)<\/font>)<\/font>;<\/font>
\n setCharacter<\/font>(<\/font>0x01<\/font>)<\/font>;<\/font>
\n delay<\/font>(<\/font>random<\/font>(<\/font>500<\/font>,1500<\/font>)<\/font>)<\/font>;<\/font><\/p>\n

x_val<\/font> =<\/font> getX<\/font>(<\/font>)<\/font>;<\/font>
\n y_val<\/font> =<\/font> getY<\/font>(<\/font>)<\/font>;<\/font>
\n z_val<\/font> =<\/font> getZ<\/font>(<\/font>)<\/font>;<\/font><\/p>\n

sum_sq<\/font> =<\/font> sqrt<\/font>(<\/font>pow<\/font>(<\/font>x_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>y_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>z_val<\/font>, 2<\/font>)<\/font>)<\/font>;<\/font><\/p>\n

delay<\/font>(<\/font>100<\/font>)<\/font>;<\/font>
\n x_val<\/font> =<\/font> getX<\/font>(<\/font>)<\/font>;<\/font>
\n y_val<\/font> =<\/font> getY<\/font>(<\/font>)<\/font>;<\/font>
\n z_val<\/font> =<\/font> getZ<\/font>(<\/font>)<\/font>;<\/font>
\nmShake<\/font> =<\/font> 0<\/font>;<\/font>
\nsum_sq_2<\/font> =<\/font> sqrt<\/font>(<\/font>pow<\/font>(<\/font>x_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>y_val<\/font>, 2<\/font>)<\/font> +<\/font> pow<\/font>(<\/font>z_val<\/font>, 2<\/font>)<\/font>)<\/font>;<\/font>
\ndiff<\/font> =<\/font> abs<\/font>(<\/font>sum_sq<\/font>–<\/font>sum_sq_2<\/font>)<\/font>;<\/font>
\nif<\/strong>(<\/font>diff<\/font> ><\/font> 300<\/font>)<\/font> {<\/strong><\/font> mShake<\/font> =<\/font> 1<\/font>;<\/font> }<\/strong><\/font>
\nif<\/strong>(<\/font>diff<\/font> ><\/font> 1000<\/font>)<\/font> {<\/strong><\/font> mShake<\/font> =<\/font> 2<\/font>;<\/font> }<\/strong><\/font>
\nif<\/strong>(<\/font>diff<\/font> ><\/font> 1200<\/font>)<\/font> {<\/strong><\/font> mShake<\/font> =<\/font> 3<\/font>;<\/font> }<\/strong><\/font><\/p>\n

\/\/Serial<\/font>.print<\/font>(<\/font>diff<\/font>)<\/font>;<\/font> Serial<\/font>.print<\/font>(<\/font>" "<\/font>)<\/font>;<\/font> Serial<\/font>.print<\/font>(<\/font>max_accel<\/font>)<\/font>;<\/font> Serial<\/font>.print<\/font>(<\/font>" "<\/font>)<\/font>;<\/font> Serial<\/font>.println<\/font>(<\/font>mShake<\/font>)<\/font>;<\/font><\/p>\n

if<\/strong>(<\/font>diff<\/font> ><\/font> max_accel<\/font>)<\/font> max_accel<\/font> =<\/font> diff<\/font>;<\/font><\/p>\n

\/\/delay<\/font>(<\/font>500<\/font>)<\/font>;<\/font><\/p>\n

if<\/strong>(<\/font>mShake<\/font> ><\/font> 0<\/font>)<\/font> {<\/strong><\/font>
\n\tmessage<\/font> =<\/font> random<\/font>(<\/font>0<\/font>,18<\/font>)<\/font>;<\/font>
\n\tfor<\/strong>(<\/font>int<\/strong> i<\/font>=<\/font>0<\/font>;<\/font> i<\/font><<\/font>3<\/font>;<\/font> i<\/font>+<\/font>+<\/font>)<\/font> {<\/strong><\/font>
\n\t\tsetCharacter<\/font>(<\/font>‘*’<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>500<\/font>)<\/font>;<\/font> setCharacter<\/font>(<\/font>‘ ‘<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>500<\/font>)<\/font>;<\/font>
\n\t}<\/strong><\/font>
\n }<\/strong><\/font> else<\/strong> {<\/strong><\/font>
\n message<\/font> =<\/font> –<\/font>1<\/font>;<\/font>
\n }<\/strong><\/font>
\n\tswitch<\/strong>(<\/font>message<\/font>)<\/font> {<\/strong><\/font>
\n\t case<\/strong> 0<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_1<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_1<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n\t break<\/strong>;<\/font>
\n\t case<\/strong> 1<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_2<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_2<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n\t case<\/strong> 2<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_3<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_3<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n\t break<\/strong>;<\/font>
\n\t case<\/strong> 3<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_4<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_4<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 4<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 5<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_5<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 6<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_6<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_6<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 7<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_7<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_7<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 8<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_8<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_8<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 9<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_9<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_9<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 10<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_10<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_10<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 11<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_11<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_11<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 12<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_12<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_12<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 13<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_13<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_13<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 14<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_14<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_14<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 15<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_15<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_15<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 16<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_16<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_16<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 17<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_17<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_17<\/font>[<\/font>i<\/font>]<\/font>)<\/font>;<\/font> delay<\/font>(<\/font>800<\/font>)<\/font>;<\/font>
\n\t\t\t\ti<\/font>+<\/font>+<\/font>;<\/font>
\n\t\t\t}<\/strong><\/font>
\n break<\/strong>;<\/font>
\n\t case<\/strong> 18<\/font>:<\/font>
\n\t\t\ti<\/font> =<\/font> 0<\/font>;<\/font>
\n\t\t\twhile<\/strong>(<\/font>mAnswer_18<\/font>[<\/font>i<\/font>]<\/font> !<\/font>=<\/font> 0x00<\/font>)<\/font> {<\/strong><\/font>
\n\t\t\t\tsetCharacter<\/font>(<\/font>mAnswer_18<\/font>[<\/font>i<\/fon<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18,84,113,156,162],"tags":[221,294,405,1195,594,721,775,1092],"yoast_head":"\nThe Ersatz Cylon Detector: A Hardware Sketch To Illuminate The Inner Workings of the MAX6953 Integrated Circuit - Near Future Laboratory<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Ersatz Cylon Detector: A Hardware Sketch To Illuminate The Inner Workings of the MAX6953 Integrated Circuit - Near Future Laboratory\" \/>\n<meta property=\"og:description\" content=\"An on-going project that requires the display of alphabetic and numeric characters using a 5x7 LED matrix turned me towards a chip by Maxim IC \u00e2\u20ac\u201d the MAX6953. The chip, while expensive (~$8), has lots of built-in features that mitigate the damage to my purse, trading such in kind for time-saved. It will directly drive up to 4 5x7 LED matrices with direct control from a microcontroller over a two-wire interface (TWI\/I2C), can manage varying intensities (16 or 32 degree scales), has a built-in Arial-like font set with a reasonably full-range of characters, diacritics and symbols, and allows me to create 24 characters of my own design. My first attempt at mucking with the chip used the DIP version, which is ginormous and requires such patience and diligence with wiring the thing up \u00e2\u20ac\u201d\u00c2 all those lines going to the pins of the LED matrix \u00e2\u20ac\u201d that I pretty much gave up after it didn't work the first time. I decided that I'd just go ahead and design a PCB for the thing and continue to hone my skills with Eagle, while also learning how to work with the MAX6953. I sent a design off, it came back, I stared at it for a few minutes, looked for the MAX6953's in my bin of samples and realized I didn't have any. I managed to coax a bunch from Maxim's sample guy, which is great. (Thanks whoever you are, wherever you are.) A couple of weeks later, when my plate was relatively clear, I assembled one of the boards, using a yellowish\/orange 5x7 matrix LED I purchased from Digikey and manufactured by LiteOn. I wanted small, but the closest I got to small was 0.7", which still seems big to me. (The story of it's assembly and problems therein is instructive if you're curious about surface-mount PCB work..and the problems therein.) I powered the thing up and, naturally enough, it didn't illuminate at all. I poked through the spec sheet and figured out that there's a whole start-up ritual you'll want to go through, such as the test mode and negating the shutdown bit, which defaults to "shutdown enabled." After an hour or so of puzzling, I managed to get it displaying characters while hooked up to my usual Arduino test harness thing. While I was assembling the board, I realized I wasn't sure what the proper orientation of the LED device should be. I looked for markings to indicate pin 1 and found nothing definitive. I looked at the product data sheet and they had an arrow pointing at pin 1 but nothing that clearly told me how to determine which of the pins was the first. Now, the holes I put in for the LED device in Eagle were a bit snug \u00e2\u20ac\u201d too snug, really. It required a bit of jiggering to get the LED device to fit. (I went back and made the holes slightly bigger in the design.) But, I realized this could be an advantage given my current pin alignment peril \u00e2\u20ac\u201d\u00c2 the snugness would allow the LED device's pins to make contact with the through-holes' platings! In other words, I could fit the device one way and not solder the pins to see if I had the thing right-way-around. Well, that worked. A consequence of it working was that some of the columns and rows didn't illuminate quite consistently \u00e2\u20ac\u201d\u00c2 they'd flicker and such \u00e2\u20ac\u201d and a mysterious character appeared \u00e2\u20ac\u201d\u00c2 an evil rabbit was the first thing I saw. I ran through a few code gyrations and got characters to show, right-way-around, so I went ahead and soldered the LED device permanently to the board, easy-peasy. Thinking of a few possible ways to make this learning project fun to share for the show-and-tell session of the weekly luncheon I have with some friends, I decided that I'd make a combination Magic 8 Ball \/ Cylon Detector, the idea being that one could reasonably ask the Magic 8 Ball if one were a Cylon \u00e2\u20ac\u201d\u00c2 I mean..why not? \u00e2\u20ac\u201d which would be a lot easier than what Baltar was trying to construct, and wouldn't require blood samples or anything. You could just ask yourself, in the privacy of your own home or a public restroom, and then choose whether or not you wanted to share your result. So, I hooked it up to an accelerometer that detects the normative shaking motion one inflicts on the Magic 8 Ball..the evil rabbit then divines the response. Anyway, it definitely works. The Ersatz Cylon Detector is meant for entertainment purposes only. It does not purport to factually report whether or not individuals are Cylons, except for Don Milvio. (He's definitely a weird hybrid Franco-Italian Cylon thing.) The results are for home amusement and cannot be used for discovery or detection of actual Cylons, their friends or family. The results cannot be used for legal purposes, nor as a sanction for physical violence. The Ersatz Cylon Detector and its results are not endorsed by the producers of Battlestar Galactica, The SciFi Channel, or its affiliates and their station managers. Arduino Code #include <Wire.h> #include <math.h> \/\/ http:\/\/wiring.org.co\/reference\/libraries\/Wire\/index.html \/\/ On the Arduino board, Analog In 4 is SDA, Analog In 5 is SCL \/\/ These correspond to pin 27 (PC4\/ADC4\/SDA) and pin 28 (PC5\/ADC5\/SCL) on the Atmega8 \/\/ The Wire class handles the TWI transactions, abstracting the nitty-gritty to make \/\/ prototyping easy. \/\/ This sketch has two TWI devices connected to it \u00e2\u20ac\u201d a LIS3LV02DQ tri-axis accelerometer \/\/ and the MAX6953 5x7 matrix LED driver. The MAX6953 is at address 0x50, and the LIS3LV02DQ is \/\/ at address 0x1D. char mAnswer_1[19] = {'S','i','g','n','s',' ','p','o','i','n','t',' ','t','o',' ','y','e','s',0x00}; char mAnswer_2[4] = {'Y','e','s',0x00}; char mAnswer_3[12] = {'M','o','s','t',' ','l','i','k','e','l','y',0x00}; char mAnswer_4[16] = {'W','i','t','h','o','u','t',' ','a',' ','d','o','u','b','t',0x00}; char mAnswer_5{16] = {'Y','e','s',',',' ','d','e','f','i','n','i','t','e','l','y',0x00}; char mAnswer_6[17] = {'A','s',' ','I',' ','s','e','e',' ','i','t',',',' ','y','e','s',0x00}; char mAnswer_7[19] = {'Y','o','u',' ','m','a','y',' ','r','e','l','y',' ','o','n',' ','i','t',0x00}; char mAnswer_8[13] = {'O','u','t','l','o','o','k',' ','g','o','o','d',0x00}; char mAnswer_9[14] = {'I','t',' ','i','s',' ','c','e','r','t','a','i','n',0x00}; char mAnswer_10[19] = {'I','t',' ','i','s',' ','d','e','c','i','d','e','d','l','y',' ','s','o',0x00}; char mAnswer_11[22] = {'R','e','p','l','y',' ','h','a','z','y',',',' ','t','r','y',' ','a','g','a','i','n',0x00}; char mAnswer_12[24] = {'B','e','t','t','e','r',' ','n','o','t',' ','t','e','l','l',' ','y','o','u',' ','n','o','w',0x00}; char mAnswer_13[16] = {'A','s','k',' ','a','g','a','i','n',' ','l','a','t','e','r',0x00}; char mAnswer_14[26] = {'C','o','n','c','e','n','t','r','a','t','e',' ','a','n','d',' ','a','s','k',' ','a','g','a','i','n',0x00}; char mAnswer_15[19] = {'C','a','n','n','o','t',' ','p','r','e','d','i','c','t',' ','n','o','w',0x00}; char mAnswer_16[18] = {'M','y',' ','s','o','u','r','c','e','s',' ','s','a','y',' ','n','o',0x00}; char mAnswer_17[14] = {'V','e','r','y',' ','d','o','u','b','t','f','u','l',0x00}; char mAnswer_18[20] = {'O','u','t','l','o','o','k',' ','n','o','t',' ','s','o',' ','g','o','o','d',0x00}; char mAnswer_19[18] = {'D','o','n',''','t',' ','c','o','u','n','t',' ','o','n',' ','i','t',0x00}; void setup() { Serial.begin(9600); CLKPR = (1<<CLKPCE); CLKPR = 0; \/\/ initialize the LIS3LV02DQ Wire.begin(); \/\/ join i2c bus (address optional for master) Wire.beginTransmission(0x1D); Wire.send(0x20); \/\/ CTRL_REG1 (20h) Wire.send(0x87); \/\/ Device on, 40hz, normal mode, all axis's enabled Wire.endTransmission(); \/\/ initialize the MAX6953 Wire.beginTransmission(0x50); Wire.send(0x07); \/\/ Display Test Wire.send(0x00); \/\/ Normal Operation Wire.endTransmission(); Wire.beginTransmission(0x50); Wire.send(0x01); \/\/ Intensity16 Wire.send(0x0F); \/\/ Full Wire.endTransmission(); Wire.beginTransmission(0x50); Wire.send(0x04); \/\/ configuration register Wire.send(0x01); \/\/ disable shutdown mode Wire.endTransmission(); initializeSpecialCharacters(); } void loop() { int z_val, x_val, y_val; int sum_sq, sum_sq_2, diff, mShake, message; int max_accel; byte i; message = 0; setCharacter(0x00); delay(random(500,1000)); setCharacter(0x01); delay(random(500,1500)); x_val = getX(); y_val = getY(); z_val = getZ(); sum_sq = sqrt(pow(x_val, 2) + pow(y_val, 2) + pow(z_val, 2)); delay(100); x_val = getX(); y_val = getY(); z_val = getZ(); mShake = 0; sum_sq_2 = sqrt(pow(x_val, 2) + pow(y_val, 2) + pow(z_val, 2)); diff = abs(sum_sq-sum_sq_2); if(diff > 300) { mShake = 1; } if(diff > 1000) { mShake = 2; } if(diff > 1200) { mShake = 3; } \/\/Serial.print(diff); Serial.print(" "); Serial.print(max_accel); Serial.print(" "); Serial.println(mShake); if(diff > max_accel) max_accel = diff; \/\/delay(500); if(mShake > 0) { message = random(0,18); for(int i=0; i<3; i++) { setCharacter('*'); delay(500); setCharacter(' '); delay(500); } } else { message = -1; } switch(message) { case 0: i = 0; while(mAnswer_1[i] != 0x00) { setCharacter(mAnswer_1[i]); delay(800); i++; } break; case 1: i = 0; while(mAnswer_2[i] != 0x00) { setCharacter(mAnswer_2[i]); delay(800); i++; } case 2: i = 0; while(mAnswer_3[i] != 0x00) { setCharacter(mAnswer_3[i]); delay(800); i++; } break; case 3: i = 0; while(mAnswer_4[i] != 0x00) { setCharacter(mAnswer_4[i]); delay(800); i++; } break; case 4: i = 0; while(mAnswer_5[i] != 0x00) { setCharacter(mAnswer_5[i]); delay(800); i++; } break; case 5: i = 0; while(mAnswer_5[i] != 0x00) { setCharacter(mAnswer_5[i]); delay(800); i++; } break; case 6: i = 0; while(mAnswer_6[i] != 0x00) { setCharacter(mAnswer_6[i]); delay(800); i++; } break; case 7: i = 0; while(mAnswer_7[i] != 0x00) { setCharacter(mAnswer_7[i]); delay(800); i++; } break; case 8: i = 0; while(mAnswer_8[i] != 0x00) { setCharacter(mAnswer_8[i]); delay(800); i++; } break; case 9: i = 0; while(mAnswer_9[i] != 0x00) { setCharacter(mAnswer_9[i]); delay(800); i++; } break; case 10: i = 0; while(mAnswer_10[i] != 0x00) { setCharacter(mAnswer_10[i]); delay(800); i++; } break; case 11: i = 0; while(mAnswer_11[i] != 0x00) { setCharacter(mAnswer_11[i]); delay(800); i++; } break; case 12: i = 0; while(mAnswer_12[i] != 0x00) { setCharacter(mAnswer_12[i]); delay(800); i++; } break; case 13: i = 0; while(mAnswer_13[i] != 0x00) { setCharacter(mAnswer_13[i]); delay(800); i++; } break; case 14: i = 0; while(mAnswer_14[i] != 0x00) { setCharacter(mAnswer_14[i]); delay(800); i++; } break; case 15: i = 0; while(mAnswer_15[i] != 0x00) { setCharacter(mAnswer_15[i]); delay(800); i++; } break; case 16: i = 0; while(mAnswer_16[i] != 0x00) { setCharacter(mAnswer_16[i]); delay(800); i++; } break; case 17 i = 0; while(mAnswer_17[i] != 0x00) { setCharacter(mAnswer_17[i]); delay(800); i++; } break; case 18: i = 0; while(mAnswer_18[i] != 0x00) { setCharacter(mAnswer_18[i<\/fon\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/\" \/>\n<meta property=\"og:site_name\" content=\"Near Future Laboratory\" \/>\n<meta property=\"article:published_time\" content=\"2007-02-24T18:58:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-08-18T18:03:01+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/farm1.static.flickr.com\/130\/401284522_1f4fbb6e9f.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@nearfuturelab\" \/>\n<meta name=\"twitter:site\" content=\"@nearfuturelab\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#organization\",\"name\":\"Near Future Laboratory\",\"url\":\"https:\/\/blog.nearfuturelaboratory.com\/\",\"sameAs\":[\"https:\/\/www.instagram.com\/nearfuturelaboratory\/\",\"https:\/\/www.linkedin.com\/company\/near-future-laboratory\/\",\"https:\/\/twitter.com\/nearfuturelab\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/blog.nearfuturelaboratory.com\/wp-content\/uploads\/2019\/10\/NearFutureLaboratoryLogo-CS4.jpg\",\"width\":1049,\"height\":206,\"caption\":\"Near Future Laboratory\"},\"image\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#website\",\"url\":\"https:\/\/blog.nearfuturelaboratory.com\/\",\"name\":\"Near Future Laboratory\",\"description\":\"Clarify Today, Design Tomorrow\",\"publisher\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/blog.nearfuturelaboratory.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/farm1.static.flickr.com\/130\/401284522_1f4fbb6e9f.jpg\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#webpage\",\"url\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/\",\"name\":\"The Ersatz Cylon Detector: A Hardware Sketch To Illuminate The Inner Workings of the MAX6953 Integrated Circuit - Near Future Laboratory\",\"isPartOf\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#primaryimage\"},\"datePublished\":\"2007-02-24T18:58:57+00:00\",\"dateModified\":\"2017-08-18T18:03:01+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/\"]}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#webpage\"},\"author\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#\/schema\/person\/4648c18232bc2e176a1197eda0225c08\"},\"headline\":\"The Ersatz Cylon Detector: A Hardware Sketch To Illuminate The Inner Workings of the MAX6953 Integrated Circuit\",\"datePublished\":\"2007-02-24T18:58:57+00:00\",\"dateModified\":\"2017-08-18T18:03:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#webpage\"},\"commentCount\":9,\"publisher\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/2007\/02\/24\/cylon-detector\/#primaryimage\"},\"keywords\":\"Accelerometer,Battlestar Galactica,Cylon,Hardware,I2C,MAX6953,New Interaction Rituals,TWI\",\"articleSection\":\"Arduino,How To,Motion,sensor,Slow Messenger\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#\/schema\/person\/4648c18232bc2e176a1197eda0225c08\",\"name\":\"Julian\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/blog.nearfuturelaboratory.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/0.gravatar.com\/avatar\/f8c8f20a3bedb22c3adce22082147ae4?s=96&d=mm&r=g\",\"caption\":\"Julian\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/posts\/300"}],"collection":[{"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":1,"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":10752,"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/posts\/300\/revisions\/10752"}],"wp:attachment":[{"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nearfuturelaboratory.com\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}