view service/garageArduino/bathroom_recv/bathroom_recv.ino @ 927:7d4dec166822

garage arduino sends brite/* color changes out on virtualwire to a digispark now Ignore-this: c14e3bd188cb97b2a7e596bb494b1e7b darcs-hash:20130929060114-312f9-f91eb21e4db5e619f165e3d1bf06c74390d7b671
author drewp <drewp@bigasterisk.com>
date Sat, 28 Sep 2013 23:01:14 -0700
parents
children 83fc811eeddd
line wrap: on
line source

/*
  board: 'Digispark (Tiny Core)'
  programmer: 'Digispark'
  
  pin 0 is the output to the LEDs
  pin 2 is the input from garage arduino
*/
#include <VirtualWire.h>

#include <Adafruit_NeoPixel.h>

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, 0, NEO_GRB + NEO_KHZ800);

#define SET(i, r, g, b) strip.setPixelColor(i, strip.Color(r, g, b)); strip.show();

int numLeds = 4;

void wakeUpPattern() { 
  for (int t = 0; t < 255; t += 2) {
    for (int i = 0; i < numLeds; i++) {
      //SET(i, 255 - t, max(0, 255 - t * 2), max(0, 255 - t * 3)); 
      SET(i, 
        (i % 2) ? (255 - t) : 0,
        (i % 2) ? 0 : (255 - t),
        (i % 2) ? (255 - t) : 0);
    }
    delay(10);
  }
  SET(0, 0, 0, 0);
  SET(1, 0, 0, 0);
  SET(2, 0, 0, 0);
  SET(3, 0, 0, 0);
}

void blinkFailedMessageError() {
  SET(0,0,0,255);
  delay(100);
  SET(0,0,0,0);
}

void blinkShortBufferError() {
  SET(0,0,255,0);
  delay(100);
  SET(0,0,0,0);
}

void setup() {
  vw_set_rx_pin(2);
  vw_setup(2000);	 // Bits per sec

  vw_rx_start();       // Start the receiver PLL running

  strip.begin();
  strip.show();

  wakeUpPattern();
}

void loop() {
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  vw_wait_rx();
  int success = vw_get_message(buf, &buflen);
  if (!success) {
    blinkFailedMessageError();
    return;
  }
  if (buflen < numLeds * 3) { 
    blinkShortBufferError();
    return;
  }

  for (int i=0; i < numLeds; i++) {
    strip.setPixelColor(i, strip.Color(
    buf[i * 3 + 0], 
    buf[i * 3 + 1], 
    buf[i * 3 + 2]));
  }
  strip.show();
}