New Location for the I am Shadowlord Blog
This blog has moved to its own domain:
Security, Projects, and Technology with tips and tricks of the trade from ShadowLord himself.

#include <SoftwareSerial.h>
//
// Message Center using Arduino and the iobridge IO-204
//
// An open-souce Shadowlord Project
// www.IamShadowlord.com
// SoftwareSerial Pins
#define rxPin 2
#define txPin 3
// Setup Software Serial
SoftwareSerial softSerial = SoftwareSerial(rxPin, txPin);
// Global Setup
int middleLED = 11;
int rightLED = 10;
int leftLED = 12;
int leftButton = 5;
int leftButtonCurrent = LOW;
int leftButtonReading;
int leftButtonPrevious = HIGH;
long leftButtonTime = 0;
long leftButtonDebounce = 200;
int middleButton = 4;
int middleButtonCurrent = LOW;
int middleButtonReading;
int middleButtonPrevious = HIGH;
long middleButtonTime = 0;
long middleButtonDebounce = 200;
int rightButton = 6;
int rightButtonCurrent = LOW;
int rightButtonReading;
int rightButtonPrevious = HIGH;
long rightButtonTime = 0;
long rightButtonDebounce = 200;
int tempPin = 5;
int tempAnalog = 0;
int tempF = 0;
char* currentRequest = "";
// Start up program
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(leftLED, OUTPUT);
pinMode(middleLED, OUTPUT);
pinMode(rightLED, OUTPUT);
pinMode(leftButton, INPUT);
pinMode(middleButton, INPUT);
pinMode(rightButton, INPUT);
softSerial.begin(9600);
delay(100);
Serial.begin(9600);
delay(100);
Serial.flush();
delay(100);
// Setup LCD
clearLCD();
setBacklightBrightness(9);
delay(1000);
// Test LEDs
digitalWrite(leftLED, HIGH);
digitalWrite(middleLED, HIGH);
digitalWrite(rightLED, HIGH);
delay(1500);
digitalWrite(leftLED, LOW);
digitalWrite(middleLED, LOW);
digitalWrite(rightLED, LOW);
}
// Start main program loop
void loop(){
// Get Analog Input and scale as temperature for ioBridge temperature sensor on arduino
tempAnalog = analogRead(tempPin);
tempF = tempAnalog / 6.875;
// Monitor left button status and debounce
leftButtonReading = digitalRead(leftButton);
if (leftButtonReading == HIGH && leftButtonPrevious == LOW && millis() - leftButtonTime > leftButtonDebounce) {
if (leftButtonCurrent == HIGH)
leftButtonCurrent = LOW;
else {
digitalWrite(leftLED, HIGH);
clearLCD();
delay(100);
softSerial.print("Outside: ");
delay(100);
softSerial.print(tempF);
delay(100);
moveCursor("02", "01");
delay(100);
softSerial.print("Atlanta: ");
leftButtonCurrent = LOW;
//Request temperature in Atlanta via ioBridge
Serial.print("[[[weather|Atlanta]]]");
digitalWrite(leftLED, LOW);
}
leftButtonTime = millis();
}
leftButtonPrevious = leftButtonReading;
// Monitor middle button status and debounce
middleButtonReading = digitalRead(middleButton);
if (middleButtonReading == HIGH && middleButtonPrevious == LOW && millis() - middleButtonTime > middleButtonDebounce) {
if (middleButtonCurrent == HIGH)
middleButtonCurrent = LOW;
else {
currentRequest = "Google";
digitalWrite(middleLED, HIGH);
clearLCD();
delay(100);
softSerial.print("GOOG: $");
delay(100);
middleButtonCurrent = LOW;
//Request Google Stock Price via ioBridge
Serial.print("[[[stock|GOOG]]]");
digitalWrite(middleLED, LOW);
}
middleButtonTime = millis();
}
middleButtonPrevious = middleButtonReading;
// Monitor right button status and debounce
rightButtonReading = digitalRead(rightButton);
if (rightButtonReading == HIGH && rightButtonPrevious == LOW && millis() - rightButtonTime > rightButtonDebounce) {
if (rightButtonCurrent == HIGH)
rightButtonCurrent = LOW;
else {
digitalWrite(rightLED, HIGH);
clearLCD();
delay(100);
softSerial.print("Alert: ");
delay(100);
rightButtonCurrent = LOW;
//Send email via ioBridge
Serial.print("[[[email|hans@nothans.com|Alert|Mom, is pressing your buttons]]]");
digitalWrite(rightLED, LOW);
}
rightButtonTime = millis();
}
rightButtonPrevious = rightButtonReading;
// Display serial messages
if(Serial.available() > 0){
delay(100);
char charIn = 0;
byte i = 0;
char stringIn[32] = "";
while(Serial.available()) {
charIn = Serial.read();
stringIn[i] = charIn;
i += 1;
}
if (currentRequest == "Google") {
softSerial.print(stringIn);
int stockPrice = atoi(stringIn);
delay(100);
moveCursor("02", "01");
delay(100);
stockPrice = stockPrice - 405;
softSerial.print("Change: $");
delay(100);
softSerial.print(stockPrice);
currentRequest = "";
}
else
softSerial.print(stringIn);
}
// End program loop
}
//
// ioBridge Serial LCD Functions and Parameters (for SoftwareSerial)
//
void displayMessage(char* message){
softSerial.print(message);
}
void clearLCD(){
softSerial.print(0xFE, BYTE);
softSerial.print("Z");
}
void setBacklightBrightness(int level){
// level
// 0=Off -> 9=Brightest
softSerial.print(0xFE, BYTE);
softSerial.print("B");
softSerial.print(level);
}
void setBacklightTime(int level, byte seconds){
// level
// 0=Off -> 9=Brightest
// seconds
// 01 = 1 seconds => 06 = 60 seconds
softSerial.print(0xFE, BYTE);
softSerial.print("T");
softSerial.print(level);
softSerial.print(seconds, BYTE);
}
void moveCursorHome(){
softSerial.print(0xFE, BYTE);
softSerial.print("H");
}
void turnCursorOn(){
softSerial.print(0xFE, BYTE);
softSerial.print("J");
}
void turnCursorOff(){
softSerial.print(0xFE, BYTE);
softSerial.print("K");
}
void turnBlinkingCursorOn(){
softSerial.print(0xFE, BYTE);
softSerial.print("P");
}
void turnBlinkingCursorOff(){
softSerial.print(0xFE, BYTE);
softSerial.print("Q");
}
void scrollMessage(int row, int speed, char* message){
// row
// 1=First Line -> 2=Second Line
// speed
// 0=Slowest -> 9=Fastest
softSerial.print(0xFE, BYTE);
softSerial.print("S");
softSerial.print(row);
softSerial.print(speed);
softSerial.print(message);
softSerial.print(0xFE, BYTE);
}
void moveCursor(char* row, char* column){
// row
// 01=First Line -> 02=Second Line
// column
// 01=First Position -> 16=Last Position
softSerial.print(0xFE, BYTE);
softSerial.print("L");
softSerial.print(row);
softSerial.print(column);
}
void drawHorizontalGauge(int row, char* leftLabel, char* rightLabel, char* length){
// row
// 1=First Line -> 2=Second Line
// leftLabel and rightLabel
// 2 character labels
// length
// a=Empty -> k=Full (filled in from left to right)
softSerial.print(0xFE, BYTE);
softSerial.print("G");
softSerial.print(row);
softSerial.print(leftLabel);
softSerial.print(rightLabel);
softSerial.print(length);
}
void drawVerticalGauge(int height){
// height
// 0=Bottom -> 8=Top (filled in from bottom to top)
softSerial.print(0xFE, BYTE);
softSerial.print("V");
softSerial.print(height);
}
| 1 | VCC | Red | +5 VDC |
| 2 | D- | White | Data - |
| 3 | D+ | Green | Data + |
| 4 | GND | Black | Ground |

Labels: api, arduino, google, iobridge, stock quote, usb, usb power cable, web 2.0