SHARE:
Uncategorized

Mentally Reframing Ruby – Part 2

Flatiron School / 16 June 2013

The following is a guest post by Kristen Curtis and originally appeared on her blog. Kristen is currently a student at The Flatiron School. You can follow her on Twitter here.

What the What with the Gmail

After my first experiment with Ruby and Arduino, I wanted to try writing a sketch that would build off of the code I had written from the blinking LED test. Using the blinking LED as an indicator, I thought it would be interesting to see if I could get my Ardunio talking with Gmail to alert me if I had any unread inbox messages. After doing some research, I found a Ruby gem called Gmail that allows me to do just that.

Requiring the Right Gems

Here we’re going to set up the sketch with the gems we’ll be running.

Board in the USA

Dino requires us to define our board, tell it that we’ll be inputing and outputing data, and tell it that we’re using a serial connection (since my Ardunio is hooked up via USB). Next, we’ll be defining our LED variable, which should be easy since it was in the previous sketch. Note: Dino also offers a good directory full of example code for setting up any given component. 

Setting up dino

You’ve Got Mail

In the next few lines of code we: call on Gmail to let us access our inbox, check if our inbox is empty, set the led variable to a resting state, and define a variable equal to the number of unread emails. Note: In the code listed below, you’d actually pass in your real email address and password.

Ruby Slippers

Now that we have access to our inbox, we can finish up this sketch by writing an if statement to blink our led when our inbox is not at zero.

0
0
1
34
198
Flatiron School
1
1
231
14.0

Normal
0

false
false
false

EN-US
JA
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}

Next Steps

I’m hoping to take this further by:

  • Writting in a delay and loop so that the sketch runs every 5-10 min
  • Adding an rgbLED so that I can light up a red LED when the inbox is full and a green LED when the inbox is empty.

Previous Post 8-Bit Git: The Challenges of Creating a Git-Based Game (Part One) Next Post