/* * Copyright (C) 2009 Jeff Epler * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ * BlinkM connections to Arduino * PWR - -- gnd -- black -- Gnd * PWR + -- +5V -- red -- 5V * I2C d -- SDA -- green -- Analog In 4 * I2C c -- SCK -- blue -- Analog In 5 */ #include "Wire.h" #include "BlinkM_funcs.h" #define BLINKM_ARDUINO_POWERED 1 // doesn't hurt byte blinkm_addr = 0x09; // the default address of all BlinkMs void setup() { Serial.begin(19200); BlinkM_begin(); delay(100); BlinkM_setFadeSpeed(blinkm_addr, 1); BlinkM_fadeToRGB(blinkm_addr, 255, 255, 255); delay(1000); BlinkM_setFadeSpeed(blinkm_addr, 20); } uint8_t colors[4][3] = { {0,16,0}, // OK {0,255,255}, // INFO {255,255,0}, // WARNING {255,0,0}, // ERROR }; static uint8_t level = 3, oldlevel=-1; static unsigned long last_message = 0x80000000ul; void loop() { unsigned long now = millis(); if(Serial.available()) { level = Serial.read(); last_message = now; } else if(now - last_message > 20*1000 && level < 3) { last_message = now; // well, sorta level ++; } // if(level != oldlevel) { level = level % 4; BlinkM_fadeToRGB(blinkm_addr, colors[level][0], colors[level][1], colors[level][2]); oldlevel = level; //} delay(50); ///digitalWrite(13, !digitalRead(13)); }