Commit 17252c38 authored by Mitchell Pomery's avatar Mitchell Pomery

Added char to Hex converter.

And screwed formatting...
parent 5d776d49
/**
BlinkenLights
Code by Mitchell Pomery [BG3] with help from Andrew Adamson [BOB]
Hardware by Andrew Adamson [BOB] with help from Mitchell Pomery [BG3]
Get the dates from the git commits.
The LED strip should be wired from the top left corner and zig zag down
* BlinkenLights
*
* Code by Mitchell Pomery [BG3] with help from Andrew Adamson [BOB]
* Hardware by Andrew Adamson [BOB] with help from Mitchell Pomery [BG3]
*
* Get the dates from the git commits.
*
* The LED strip should be wired from the top left corner and zig zag down
*
*/
///TODO: Vary light pattern randomly
......@@ -49,20 +49,62 @@ int position = 0; // How far through the cycle we are
struct led ledArray[STRIPLENGTH]; // led array
int lightOption = 1; // Which predefined light sequence we are running
char brightness = (char) 128; //Brightness of the LEDs
// We seem to have issues at the moment putting this up to the maximum (255)
// Most likely due to the fact the LED strip is underpowered
// We seem to have issues at the moment putting this up to the maximum (255)
// Most likely due to the fact the LED strip is underpowered
// Network Settings
static uint8_t mac[] = { 0xC0, 0xCA, 0xC0, 0x1A, 0x19, 0x82 }; // C0CA C01A 1982
static uint8_t mac[] = {
0xC0, 0xCA, 0xC0, 0x1A, 0x19, 0x82 }; // C0CA C01A 1982
IPAddress ip(130,95,13,96); // 130.95.13.96 (Can we forcefully take .82?
// If we remove the ip address, we will automatically use DHCP
// Set up our light strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIPLENGTH, PIN,
NEO_GRB + NEO_KHZ800);
NEO_GRB + NEO_KHZ800);
// Set up our webserver
WebServer webserver(PREFIX, 80);
// =========================== char-hex conversions ===========================
char* charToHex(char c) {
char base_digits[16] =
{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
int converted_number[64];
int base = 16;
int next_digit, index=0;
int number_to_convert = (int) c + 128;
/* convert to the indicated base */
while (number_to_convert != 0)
{
converted_number[index] = number_to_convert % base;
number_to_convert = number_to_convert / base;
index++;
}
Serial.println(index);
/* now print the result in reverse order */
index--; /* back up to last entry in the array */
if (index < 0) {
Serial.print(base_digits[0]);
}
if (index < 1) {
Serial.print(base_digits[0]);
}
for(; index>=0; index--) /* go backward through array */
{
Serial.print(base_digits[converted_number[index]]);
}
return (char) 0;
}
// ============================ LIGHT MANIPULATION ============================
/**
......@@ -181,11 +223,11 @@ char *url_tail, bool tail_complete) {
if (rc != URLPARAM_EOS) {
if (String(name).equals("seq")) {
lightOption = atoi(value);
server.print(lightOption);
position = 0;
}
}
}
server.print(lightOption);
}
else {
server.print("Unknown Request");
......@@ -199,8 +241,8 @@ char *url_tail, bool tail_complete) {
* @param url_tail
* @param tail_complete
*/
void webSetLED(WebServer &server, WebServer::ConnectionType type,
char *url_tail, bool tail_complete) {
/*void webSetLED(WebServer &server, WebServer::ConnectionType type,
char *url_tail, bool tail_complete) {
URLPARAM_RESULT rc;
char name[NAMELEN];
char value[VALUELEN];
......@@ -243,7 +285,7 @@ char *url_tail, bool tail_complete) {
if (xPos != -1 && yPos != -1 && r != -1 && g != -1 && b != -1) {
setLED(xPos, r, g, b);
}
}
}*/
/**
* Set the brightness to a specific magnitude
......@@ -270,11 +312,12 @@ char *url_tail, bool tail_complete) {
if (rc != URLPARAM_EOS) {
if (String(name).equals("bright")) {
strip.setBrightness(atoi(value));
server.print(atoi(value));
strip.show();
}
}
}
server.print((int) brightness);
Serial.println((int) brightness);
}
else {
server.print("Unknown");
......@@ -393,10 +436,12 @@ void theaterChaseRainbow(uint8_t wait) {
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
}
else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
}
else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
......@@ -416,7 +461,7 @@ void setup() {
// Set up webpages
webserver.setDefaultCommand(&webSetSequence);
webserver.addCommand("custom", &webSetSequence);
webserver.addCommand("individual", &webSetLED);
//webserver.addCommand("individual", &webSetLED);
webserver.addCommand("brightness", &webSetBrightness);
// Start Webserver
webserver.begin();
......@@ -427,6 +472,15 @@ void setup() {
ledArray[i].blue = (char) 128;
}
for (int i = -128; i < 128; i++) {
Serial.print(i);
Serial.print(" ");
//Serial.print((char) i);
Serial.print(" ");
charToHex((char) i);
Serial.println("");
}
// Start Lights
strip.begin();
strip.setBrightness(128);
......@@ -475,3 +529,4 @@ void loop()
lightOption++;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment