Skip to content

Commit

Permalink
updated to hue bright sat up/down basic api after workshop 22/4
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelpusher committed Apr 22, 2015
1 parent e6a9e5c commit e91af0c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Arduino/NEOPIXELS/neopixsimpleserial/HSVColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ class HSVColori
HSVColori& shiftHue(int amt)
{
h = (h + amt) & 0xFF;

return *this;
}

HSVColori& brighten(int amt)
{
v = (v + amt) & 0xFF;
return *this;
}

HSVColori& saturate(int amt)
{
s = (s + amt) & 0xFF;
return *this;
}

// Convert a color in H,S,V to RGB
Expand Down
84 changes: 70 additions & 14 deletions Arduino/NEOPIXELS/neopixsimpleserial/neopixsimpleserial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

HSVColori myColor(100,255,200); // h,s,v
HSVColori myColor(100,255,100); // h,s,v

int inc = 2;



void setup() {

Serial.begin(9600);
Serial.begin(9600);

myColor.h = 0; //red

Expand All @@ -48,29 +51,82 @@ void loop() {
Serial.print("received byte:");
Serial.println((char)inByte);

char received = (char)inByte;
char received = (char) inByte;

if ( received == 'h')
{
myColor.shiftHue(4);
}
else if ( received == 'H')
switch( received )
{
myColor.shiftHue(-4);

case 'h':
{
myColor.shiftHue(inc);
}
break;

case 'H':
{
myColor.shiftHue(-inc);
}
break;

case 's':
{
myColor.saturate(inc);
}
break;

case 'S':
{
myColor.saturate(-inc);
}
break;

case 'b':
{
myColor.brighten(inc);
}
break;

case 'B':
{
myColor.brighten(-inc);
}
break;


case 'R':
case 'r':
{
myColor.h = 0;
myColor.s = 200;
myColor.v = 100;
}
break;

default:
break;
}

// end switch received bytes


Serial.print(myColor.h);
Serial.print(",");
Serial.print(myColor.s);
Serial.print(",");
Serial.println(myColor.v);


// get color object as R,G,B array for neopixels

uint32_t c = myColor.toRGB();

for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, c );
pixels.show(); // This sends the updated pixel color to the hardware.
}
// end serial available
// end serial available
}

}


0 comments on commit e91af0c

Please sign in to comment.