Changeset - b7fb7b2649fd
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 10 years ago 2015-06-13 06:39:03
drewp@bigasterisk.com
bug in setting rgb
Ignore-this: 380aa2d0c907faf69749636426d8de17
2 files changed with 2 insertions and 7 deletions:
0 comments (0 inline, 0 general)
light9/effecteval/effectloop.py
Show inline comments
 
@@ -193,49 +193,49 @@ class ControlBoard(object):
 
        which: 0 or 1 to pick the strip
 
        pixels: (50, 3) array of 0..1 floats
 
        """
 
        command = {0: '\x00', 1: '\x01'}[which]
 
        if pixels.shape != (50, 3):
 
            raise ValueError("pixels was %s" % pixels.shape)
 
        self._dev.write('\x60' + command + self._8bitMessage(pixels))
 
        self._dev.flush()
 

	
 
    def setUv(self, which, level):
 
        """
 
        which: 0 or 1
 
        level: 0 to 1
 
        """
 
        command = {0: '\x02', 1: '\x03'}[which]
 
        self._dev.write('\x60' + command + chr(max(0, min(1, level)) * 255))
 
        self._dev.flush()
 

	
 
    def setRgb(self, color):
 
        """
 
        color: (1, 3) array of 0..1 floats
 
        """
 
        if color.shape != (1, 3):
 
            raise ValueError("color was %s" % color.shape)
 
        self._dev.write('\x60\x04%s' + self._8bitMessage(color))
 
        self._dev.write('\x60\x04' + self._8bitMessage(color))
 
        self._dev.flush()
 

	
 
        
 
class LedLoop(EffectLoop):
 
    def initOutput(self):
 
        self.board = ControlBoard()
 
        self.lastSent = {} # what's in arduino's memory
 
        
 
    def combineOutputs(self, outputs):
 
        combined = {'L': Z, 'R': Z,
 
                    'blacklight0': 0, 'blacklight1': 0,
 
                    'W': numpy.zeros((1, 3), dtype=numpy.float16)}
 
        
 
        for out in outputs:
 
            log.debug('combine output %r', out)
 
            if isinstance(out, Effects.Blacklight):
 
                key = 'blacklight%s' % out.which
 
                combined[key] = max(combined[key], out)
 
            elif isinstance(out, Effects.Strip):
 
                pixels = numpy.array(out.pixels, dtype=numpy.float16)
 
                for w in out.which:
 
                    combined[w] = numpy.maximum(
 
                        combined[w], pixels[:1,:] if w == 'W' else pixels)
 
                
rgbled/nanostrip.cc
Show inline comments
 
@@ -34,54 +34,49 @@ void intro() {
 
    strip->setPixelColor(0,   red); strip->show(); delay(100);
 
    strip->setPixelColor(0, black); strip->show(); delay(100);
 
  }
 
}
 

	
 
void setStrip(Adafruit_NeoPixel* strip) {
 
  digitalWrite(debugLed, 1);
 
  for (uint8_t i=0; i < strip->numPixels(); i++) {
 
    while (Serial.available() < 3) {
 
    }
 
    byte r = Serial.read();
 
    byte g = Serial.read();
 
    byte b = Serial.read();
 
    strip->setPixelColor(i, strip->Color(g, r, b));
 
  }
 
  strip->show();
 

	
 
  digitalWrite(debugLed, 0);
 
}
 

	
 
int main(void) {
 
  init();
 
  pinMode(debugLed, OUTPUT);
 

	
 
  pinMode(3, OUTPUT);
 
  pinMode(6, OUTPUT);
 
  pinMode(9, OUTPUT);
 
  pinMode(10, OUTPUT);
 
  pinMode(11, OUTPUT);
 
  
 
    
 
  strip0.begin();
 
  strip1.begin();
 
  intro(); 
 
  Serial.begin(115200);
 
 
 
  uint8_t i;
 
  while (1) {
 
    while (Serial.available() <= 2) {
 
    }
 
    i = Serial.read();
 
    if (i != 0x60) {
 
      continue;
 
    }
 
    i = Serial.read(); // command
 
    if (i == 0) { // set strip: 0x60 0x00 <numPixels * 3 bytes>
 
      setStrip(&strip0);
 
    } else if (i == 1) { // strip 1
 
      setStrip(&strip1);
 
    } else if (i == 2) { // set pwm on uv1: 0x60 0x02 <level>
 
      while (Serial.available() < 1) {
 
      }
 
      analogWrite(3, Serial.read());
 
    } else if (i == 3) { // set pwm on uv2: 0x60 0x03 <level>
 
      while (Serial.available() < 1) {
0 comments (0 inline, 0 general)