Got the time?

Showcase your projects! We love to see what people come up with, so please share your creations here.
Post Reply
Things
Posts: 36
Joined: Mon Aug 26, 2013 3:47 pm
Location: Cairns, Australia
Contact:

Got the time?

Post by Things » Fri Oct 23, 2015 1:14 am

I completed this project just over a year ago now and realized I never even shared it. It's a giant 7seg RGB clock I built because "why not" (and with inspiration from Sparkfun's green-only version). Originally I was going to use non-addressable LED strip with individual drivers but the wiring was too much of a pain, so I went for addressable pixels instead. The digit "modules" can be connected in any order and are mounted on a couple aluminium strips to make hanging easier. Runs off an Arduino (of course), has ambient light sensing, a basic menu system for setting time, 12/24h mode etc, and also has bluetooth for changing the colours/patterns, and putting it into countdown/count up modes. Above all it looks awesome on my wall, you can see it from out on the street. Everyone comments on it :D

Image

Image

Image

Each digit is A3 sized as that was the largest I could do in my laser cutter. Was planning on bigger initially but this is a reasonable size, and it packs away neatly too :)

Image

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Got the time?

Post by andrew » Fri Oct 23, 2015 2:55 am

Awesome, thank you for sharing that with us.
Would be great for countdowns as well (NYE, days until x, etc.)

Things
Posts: 36
Joined: Mon Aug 26, 2013 3:47 pm
Location: Cairns, Australia
Contact:

Re: Got the time?

Post by Things » Fri Oct 23, 2015 3:45 pm

Cheers :)

Haven't used the countdown functionality much .. just spends all day being a clock. Has been running essentially non stop for a bit over a year now and it's going great. Did accidentally kill a few of the LED pixels a while back but didn't take long to find and replace them. Thinking maybe it could also take a feed from the WiFi weather station I'm working on at the moment .. hmm.

Here's the code for anyone wondering how I defined the digits and mapped colours to them:

Code: Select all

#include <avr/pgmspace.h>
PROGMEM byte digits[14][29] = {
{24,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}, // 0
{8,8,9,10,11,12,13,14,15}, // 1
{20,4,5,6,7,8,9,10,11,16,17,18,19,20,21,22,23,24,25,26,27}, // 2
{20,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,25,26,27}, // 3
{16,0,1,2,3,8,9,10,11,12,13,14,15,24,25,26,27}, // 4
{20,0,1,2,3,4,5,6,7,12,13,14,15,16,17,18,19,24,25,26,27}, // 5
{24,0,1,2,3,4,5,6,7,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}, // 6
{12,4,5,6,7,8,9,10,11,12,13,14,15}, // 7
{28,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}, // 8
{24,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,25,26,27},// 9
{20,0,1,2,3,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}, // b
{24,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,20,21,22,23,24,25,26,27}, // A
{4,24,25,26,27}, // -
{16,0,1,2,3,4,5,6,7,20,21,22,23,24,25,26,27} // f
};
#include <Wire.h>
#include <Button.h>
#include <RTClib.h>
#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(120, 11, NEO_GRB + NEO_KHZ800);
RTC_BQ32000 RTC;
byte hour; // Either 12 or 24h time
byte oldsec; // For flashing divider
byte maxbright = EEPROM.read(0); // Manual brightness
byte autobright = EEPROM.read(2); // Limit of auto brightness
boolean sectog = false; // Flashing divider
const int numReadings = 100; // LDR smoothing
Button buttonSet = Button(5, PULLUP);
Button buttonUp = Button(6, PULLUP);
Button buttonDown = Button(7, PULLUP);
int readings[numReadings];      
int index = 0;                  
long total = 0;                  
int average = 0;               
boolean setting = false; // Whether we're in the menu
byte setMode = 1; // Current menu option
boolean disableDisp = false; // Disable clock update
byte setbright; // Final brightness value
boolean timeFormat = EEPROM.read(1); // Read in 12/24h format
boolean Serialdata = false; // Whether there is new serial data
long count = 0; // For the countdown functionality
boolean counting = false; // Whether we're counting
char c, t;  // For the serial input
int nnn;
byte colours[28][3];  // Array of segment colours
byte colswitch = 0;  // For segment colour function
float incr = 1;
boolean cdown = false;

void setup() {
    Serial.begin(115200);
    Wire.begin();
    RTC.begin();
    strip.begin();
    sclear();
    pinMode(A3, OUTPUT);
    digitalWrite(A3, LOW);
    pinMode(13, OUTPUT);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    // following line sets the RTC to the date & time this sketch was compiled
    //RTC.adjust(DateTime(__DATE__, __TIME__));  
    RTC.setIRQ(0); // IRQ square wave disabled
    //RTC.setIRQ(1); // 1Hz square wave on IRQ
    //RTC.setIRQ(2); // 512Hz square wave on IRQ
    
    // If the IRQ square wave output is disabled this method will set the IRQ pin's 
    // state to either HIGH or LOW:
    RTC.setIRQLevel(HIGH);
    RTC.setCalibration(0);
    // Set to a value in the range [-31,31] to adjust clock frequency
    RTC.setCharger(0); // Disabled
    //RTC.setCharger(1); // Charge voltage = VCC-0.5V
    //RTC.setCharger(2); // Charge voltage = VCC
    
    for (int i = 0; i<28; i++){
    float h = i/28.0000;
    int redvar;
    int bluevar;
    int greenvar;
    h2rgb(h, redvar, greenvar, bluevar);
    colours[i][0] = redvar;
    colours[i][1] = greenvar;
    colours[i][2] = bluevar;
    }
    /*for (int i = 0; i < 28; i = i + 7) {
      colours[i][0] = 255;
      colours[i][1] = 0;
      colours[i][2] = 0;
      colours[i+1][0] = 255;
      colours[i+1][1] = 128;
      colours[i+1][2] = 0;
      colours[i+2][0] = 255;
      colours[i+2][1] = 255;
      colours[i+2][2] = 0;
      colours[i+3][0] = 0;
      colours[i+3][1] = 255;
      colours[i+3][2] = 0;
      colours[i+4][0] = 0;
      colours[i+4][1] = 255;
      colours[i+4][2] = 128;
      colours[i+5][0] = 0;
      colours[i+5][1] = 128;
      colours[i+5][2] = 255;
      colours[i+6][0] = 0;
      colours[i+6][1] = 0;
      colours[i+6][2] = 255;
    }*/
    
    /*for (int i = 0; i < 28; i++) {
      if (i < 4) {
      colours[i][0] = 255;
      colours[i][1] = i * 28;
      colours[i][2] = 0;
    }
    if (i < 8 && i >= 4) {
      colours[i][0] = 255/(i-4);
      colours[i][1] = 255;
      colours[i][2] = 0;
    }
    if (i < 12 && i >= 8) {
      colours[i][0] = 0;
      colours[i][1] = 255;
      colours[i][2] = (i-8)*28;
    }
    if (i < 16 && i >= 12) {
      colours[i][0] = 0;
      colours[i][1] = 255/(i-12);
      colours[i][2] = 255;
    }
    if (i < 20 && i >= 16) {
      colours[i][0] = (i-16)*28;
      colours[i][1] = 0;
      colours[i][2] = 255;
    }
    if (i < 24 && i >= 20) {
      colours[i][0] = 255;
      colours[i][1] = (i-20)*28;
      colours[i][2] = 255;
    }
   if (i < 28 && i >= 24) {
      colours[i][0] = 255;
      colours[i][1] = 255;
      colours[i][2] = 255;
    }
    }*/
 }

void loop() {

   DateTime now = RTC.now();
   if (timeFormat == true){ // Convert to 12h time
      if (now.hour() > 12) {
        hour = now.hour() - 12;
      } else{
         hour = now.hour();
      }  
    } else{
       hour = now.hour();
    } 
   if (maxbright == 1){
    checkLDR();
   } else{
     setbright = map(maxbright,0,99,0,255);
     //strip.setBrightness(setbright);
   }
    if (disableDisp == false){
    if (hour < 10){
      drawdig(1,8,0,0,0);
    } else{
      //drawdig(1,(hour%100/10),setbright,0,0); // Single digit colour
      drawdig(1,(hour%100/10)); // Per segment colour
    }
    if (hour == 0){
      drawdig(1,0);
    }
    // Single digit colour
    /*drawdig(2,(hour%10),setbright,setbright/4,0); 
    drawdig(3,(now.minute()%100/10),0,setbright,setbright/2);
    drawdig(4,(now.minute()%10),0,0,setbright);*/
    // Per segment colour
    drawdig(2,(hour%10));
    drawdig(3,(now.minute()%100/10));
    drawdig(4,(now.minute()%10));
    int dotcol = map(now.second(), 0, 59, 0, setbright);
    if (oldsec != now.second()) {
      oldsec = now.second();
      if (sectog == false){
      drawd(dotcol,setbright-dotcol,0);
      sectog = true;
    } else{
      drawd(0,0,0);
      sectog = false;
    }
    }
    strip.show();
    }
    // Button check routine
    if (buttonSet.uniquePress() || setting == true){
      setting = true;
      if (setMode == 1){ // Adjust hours
        delay(200);
        drawdig(1,(hour%100/10),0,0,0);
        drawdig(2,(hour%10),0,0,0);
        strip.show();
        delay(200);
        if (buttonUp.isPressed()) {
          DateTime curr = RTC.now();  // get current time
          DateTime PlusOne (curr.get() + 3600); // add one hour
          RTC.adjust(PlusOne); // set to new time
        }
        if (buttonDown.isPressed()) {
          DateTime curr = RTC.now();  // get current time
          DateTime PlusOne (curr.get() - 3600); // add one hour
          RTC.adjust(PlusOne); // set to new time
        }
      }
      if (setMode == 2){ // Adjust minutes
        delay(200);
        drawdig(3,(now.minute()%100/10),0,0,0);
        drawdig(4,(now.minute()%10),0,0,0);
        strip.show();
        delay(200);
        if (buttonUp.isPressed()) {
          DateTime curr = RTC.now();  // get current time
          DateTime PlusOne (curr.get() + 60); // add one min
          RTC.adjust(PlusOne); // set to new time
        }
        if (buttonDown.isPressed()) {
          DateTime curr = RTC.now();  // get current time
          DateTime PlusOne (curr.get() - 60); // add one min
          RTC.adjust(PlusOne); // set to new time
        }
      }
      if (setMode == 3){
        disableDisp = true;
        drawd(0,0,0);
        drawdig(1,10,setbright,0,0);
        drawdig(2,12,setbright,0,0);
        drawdig(3,maxbright%100/10,setbright,0,0);
        drawdig(4,maxbright%10,setbright,0,0);
        if (maxbright == 1){
            drawdig(3,8,0,0,0);
            drawdig(4,11,setbright,0,0);
        }
        strip.show();
        if (buttonUp.isPressed()) {
          if (maxbright < 100){
            maxbright++;
          }
          if (maxbright == 100){
            maxbright = 1;
          }
          delay(150);
        }
        if (buttonDown.isPressed()) {
          if (maxbright > 0){
            maxbright--;
          }
          if (maxbright == 0){
            maxbright = 99;
          }
          delay(150);
        }
      }
      if (setMode == 4){
        disableDisp = true;
        drawd(0,0,0);
        drawdig(1,11,setbright,0,0);
        drawdig(2,10,setbright,0,0);
        drawdig(3,autobright%100/10,setbright,0,0);
        drawdig(4,autobright%10,setbright,0,0);
        strip.show();
        if (buttonUp.isPressed()) {
          if (autobright < 100){
            autobright++;
          }
          if (autobright == 100){
            autobright = 1;
          }
          delay(150);
        }
        if (buttonDown.isPressed()) {
          if (autobright > 0){
            autobright--;
          }
          if (autobright == 0){
            autobright = 99;
          }
          delay(150);
        }
      }
      if (setMode == 5){
        disableDisp = true;
        drawdig(1,13,setbright,0,0);
        drawdig(2,12,setbright,0,0);
        if (timeFormat == true){
          drawdig(3,1,setbright,0,0);
          drawdig(4,2,setbright,0,0);
        } else {
          drawdig(3,2,setbright,0,0);
          drawdig(4,4,setbright,0,0);
        }
        strip.show();
        if (buttonUp.uniquePress()) {
           timeFormat = true;
        }
        if (buttonDown.uniquePress()) {
          timeFormat = false;
        }
      }
      if (buttonSet.uniquePress()) {
        setMode++;
      }
      if (setMode == 6){
        EEPROM.write(0,maxbright);
        EEPROM.write(1,timeFormat);
        EEPROM.write(2,autobright);
        disableDisp = false;
        setting = false;
        setMode = 1;
      }
    }

  if(Serial.available() > 0) // If there is data to read
   { 
	 c = Serial.read(); // Get a character
	 delay(5);
	 if(c >= 'a' && c <= 'z') // If it's a command
	 {
	    nnn = 0;
	    while(Serial.available() > 0) // While there is still data
	    {  
                  //Serial.println("Looping");
		 t = Serial.read(); // Read next character

		 if(t == ',' || t == ' '){
		   continue; // Skip commas and spaces
                  }
		 if(t >= '0' && t <= '9') // If it's a number
		 {
		    nnn *= 10; // Multiply previous value by 10
		    nnn += t - '0'; // Add the new digit
		 }
		 else {
		    break;
                  }
		 //delay(10);
	    }
	 }
      if (c == 'i' || c == 'd' || c == 'u'){
        sclear();
        disableDisp = true;
        counting = false;
      } else {
        disableDisp = false;
      }
    Serialdata = true;
    switch(c) {
      case 'i': Serial.println("Ready for data"); break;
      case 'd': Serial.print("Counting down from "); Serial.print(nnn); Serial.print("s"); Serial.println(""); break;
      case 'u': Serial.print("Counting up to "); Serial.print(nnn); Serial.print("s"); Serial.println(""); break;
      case 'b': Serial.print("Setting brightness to "); Serial.print(nnn); Serial.println(""); break;
      case 'a': Serial.print("Setting all digit colours to "); Serial.print(nnn); Serial.println(""); break;
      case 'p': Serial.print("Setting pattern to "); Serial.print(nnn); Serial.println(""); break;
    }
    }
   switch (c) {
     case 'd':
       if (counting == false){
       count = (now.get() + nnn);
       counting = true;
       drawd(setbright,0,0);
       }
       if (count > now.get()){
       drawdig(1,(count-now.get())/60/10%10,setbright,0,0);
       drawdig(2,(count-now.get())/60%10,setbright,0,0);
       drawdig(3,(count-now.get())%60/10%10,setbright,0,0);
       drawdig(4,(count-now.get())%60%10,setbright,0,0);
       strip.show();
       }
       if (count-now.get() < 1){
         if (oldsec != now.second()) {
          oldsec = now.second();
          if (sectog == false){
          drawdig(1,0,setbright,0,0);
          drawdig(2,0,setbright,0,0);
          drawdig(3,0,setbright,0,0);
          drawdig(4,0,setbright,0,0);
          drawd(setbright,0,0);
          sectog = true;
        } else{
          drawdig(1,0,0,0,0);
          drawdig(2,0,0,0,0);
          drawdig(3,0,0,0,0);
          drawdig(4,0,0,0,0);
          drawd(0,0,0);
          sectog = false;
        }
        strip.show();
       }
       }
       break;
       
     case 'u':
      if (counting == false){
       count = (now.get() + nnn);
       counting = true;
       drawd(setbright,0,0);
       }
       if (count < now.get()){
       drawdig(1,(now.get()-count)/60/10%10,setbright,0,0);
       drawdig(2,(now.get()-count)/60%10,setbright,0,0);
       drawdig(3,(now.get()-count)%60/10%10,setbright,0,0);
       drawdig(4,(now.get()-count)%60%10,setbright,0,0);
       strip.show();
       }
       /*if (count+now.get() > nnn){
         if (oldsec != now.second()) {
          oldsec = now.second();
          if (sectog == false){
          drawdig(1,0,setbright,0,0);
          drawdig(2,0,setbright,0,0);
          drawdig(3,0,setbright,0,0);
          drawdig(4,0,setbright,0,0);
          drawd(setbright,0,0);
          sectog = true;
        } else{
          drawdig(1,0,0,0,0);
          drawdig(2,0,0,0,0);
          drawdig(3,0,0,0,0);
          drawdig(4,0,0,0,0);
          drawd(0,0,0);
          sectog = false;
        }
        strip.show();
       }
       }*/
       break;
     
     case 'b':
       maxbright = constrain(nnn,1,255);
     break;
     case 'a':
     {
            float h = constrain(nnn,0,255)/255.00000;
            int redvar;
            int bluevar;
            int greenvar;
            h2rgb(h, redvar, greenvar, bluevar);
         for (int i = 0; i<28; i++){
            colours[i][0] = redvar;
            colours[i][1] = greenvar;
            colours[i][2] = bluevar;
         }
    break;
     }
    
    case 'p':
      switch(nnn) {
        case 1: 
             for (int i = 0; i<28; i++){
                float h = (incr/100.0000);
                int redvar;
                int bluevar;
                int greenvar;
                h2rgb(h, redvar, greenvar, bluevar);
                colours[i][0] = redvar;
                colours[i][1] = greenvar;
                colours[i][2] = bluevar;
                if (incr < 100){
                  incr = incr + 0.01;
                } else{
                  incr = 0.01;
                }
               }
               break;
          case 2:
              for (int i = 0; i < 28; i = i + 7) {
                colours[i][0] = 255;
                colours[i][1] = 0;
                colours[i][2] = 0;
                colours[i+1][0] = 255;
                colours[i+1][1] = 128;
                colours[i+1][2] = 0;
                colours[i+2][0] = 255;
                colours[i+2][1] = 255;
                colours[i+2][2] = 0;
                colours[i+3][0] = 0;
                colours[i+3][1] = 255;
                colours[i+3][2] = 0;
                colours[i+4][0] = 0;
                colours[i+4][1] = 255;
                colours[i+4][2] = 128;
                colours[i+5][0] = 0;
                colours[i+5][1] = 128;
                colours[i+5][2] = 255;
                colours[i+6][0] = 0;
                colours[i+6][1] = 0;
                colours[i+6][2] = 255;
              }
              break;
          case 3:
              for (int i = 0; i < 28; i++) {
                if (i < 4) {
                colours[i][0] = 255;
                colours[i][1] = i * 28;
                colours[i][2] = 0;
              }
              if (i < 8 && i >= 4) {
                colours[i][0] = 255/(i-4);
                colours[i][1] = 255;
                colours[i][2] = 0;
              }
              if (i < 12 && i >= 8) {
                colours[i][0] = 0;
                colours[i][1] = 255;
                colours[i][2] = (i-8)*28;
              }
              if (i < 16 && i >= 12) {
                colours[i][0] = 0;
                colours[i][1] = 255/(i-12);
                colours[i][2] = 255;
              }
              if (i < 20 && i >= 16) {
                colours[i][0] = (i-16)*28;
                colours[i][1] = 0;
                colours[i][2] = 255;
              }
              if (i < 24 && i >= 20) {
                colours[i][0] = 255;
                colours[i][1] = (i-20)*28;
                colours[i][2] = 255;
              }
             if (i < 28 && i >= 24) {
                colours[i][0] = 255;
                colours[i][1] = 255;
                colours[i][2] = 255;
              }
              }
          break;
          case 4:
              for (int i = 0; i<28; i++){
              float h = i/28.0000;
              int redvar;
              int bluevar;
              int greenvar;
              h2rgb(h, redvar, greenvar, bluevar);
              colours[i][0] = redvar;
              colours[i][1] = greenvar;
              colours[i][2] = bluevar;
              }
        break;
      }
      break;
       
   }
}

void checkLDR() {
    // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor:  
  readings[index] = analogRead(A0); 
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array:  
  index = index + 1;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // send it to the computer as ASCII digits
  setbright = map(average,0,1000,4,map(autobright,0,99,0,255));
}

void sclear(){
  for (int c = 0; c<120; c++){
    strip.setPixelColor(c,0,0,0);
  }
  strip.show();
}
// Draw dots
void drawd (int r, int g, int b) {
  strip.setPixelColor(56,r,g,b);
  strip.setPixelColor(57,r,g,b);
  strip.setPixelColor(58,r,g,b);
  strip.setPixelColor(59,r,g,b);
  strip.setPixelColor(60,r,g,b);
  strip.setPixelColor(61,r,g,b);
  strip.setPixelColor(62,r,g,b);
  strip.setPixelColor(63,r,g,b);
}
  
void drawdig(int dig, int num, int r, int g, int b) { // Function for RGB
  switch (dig) { // Determines which pixel is the start of each digit
    case 1:
    dig = 0;
    break;
    case 2:
    dig = 28;
    break;
    case 3:
    dig = 64;
    break;
    case 4:
    dig = 92;
    break;
  }
  byte pixOut = pgm_read_byte(&(digits[num][0]));
  boolean checked[28] = {}; // Array to store missing numbers
  for (int j = 0; j<28; j++){ // Fill it with 0's
    checked[j] = 0;
  }
  for (int i = 0; i<28; i++) { // Check if the arrays are missing any pixels
    for (int k = 1; k<pixOut+1; k++) {
      if (pgm_read_byte(&(digits[num][k])) == i){  // ANd if they are, set them to 0
        checked[i] = 1;
      } 
    }
  }
  for (int i = 0; i<28; i++) { // Pixels that are missing, turn them off
    if (checked[i] == 0){
      strip.setPixelColor(i+dig,0,0,0);
    }
  }
  for (int i = 1; i<pixOut+1; i++) { // Output the rest of the given pixels
    strip.setPixelColor(pgm_read_byte(&(digits[num][i]))+dig,r,g,b);
  }
}

void drawdig(int dig, int num) { // Function for per-segment colours
  switch (dig) { // Determines which pixel is the start of each digit
    case 1:
    dig = 0;
    colswitch = 0;
    break;
    case 2:
    dig = 28;
    colswitch = 7;
    break;
    case 3:
    dig = 64;
    colswitch = 14;
    break;
    case 4:
    dig = 92;
    colswitch = 21;
    break;
  }
  byte pixOut = pgm_read_byte(&(digits[num][0]));
  boolean checked[28] = {}; // Array to store missing numbers
  for (int j = 0; j<28; j++){ // Fill it with 0's
    checked[j] = 0;
  }
  for (int i = 0; i<28; i++) { // Check if the arrays are missing any pixels
    for (int k = 1; k<pixOut+1; k++) {
      if (pgm_read_byte(&(digits[num][k])) == i){  // ANd if they are, set them to 0
        checked[i] = 1;
      } 
    }
  }
  int colindex = colswitch;
  for (int k = dig; k < dig + 28; k = k + 4) {
      int col1 = map(colours[colindex][0],0,255,0,setbright);
      int col2 = map(colours[colindex][1],0,255,0,setbright);
      int col3 = map(colours[colindex][2],0,255,0,setbright);
      strip.setPixelColor(k, col1, col2, col3);
      strip.setPixelColor(k+1, col1, col2, col3);
      strip.setPixelColor(k+2, col1, col2, col3);
      strip.setPixelColor(k+3, col1, col2, col3);
     colindex++;
    }
  for (int i = 0; i<28; i++) { // Pixels that are missing, turn them off
    if (checked[i] == 0){
      strip.setPixelColor(i+dig,0,0,0);
    }
  }
  for (int i = 1; i<pixOut+1; i++) { // Output the rest of the given pixels
    byte actualPix = pgm_read_byte(&(digits[num][i]));
    strip.setPixelColor(actualPix+dig,strip.getPixelColor(actualPix+dig));
  }
}

void h2rgb(float H, int& R, int& G, int& B) {

  int var_i;
  float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  if ( S == 0 )                       //HSV values = 0 ÷ 1
  {
    R = V * 255;
    G = V * 255;
    B = V * 255;
  }
  else
  {
    var_h = H * 6;
    if ( var_h == 6 ) var_h = 0;      //H must be < 1
    var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
    var_1 = V * ( 1 - S );
    var_2 = V * ( 1 - S * ( var_h - var_i ) );
    var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

    if      ( var_i == 0 ) {
      var_r = V     ;
      var_g = var_3 ;
      var_b = var_1 ;
    }
    else if ( var_i == 1 ) {
      var_r = var_2 ;
      var_g = V     ;
      var_b = var_1 ;
    }
    else if ( var_i == 2 ) {
      var_r = var_1 ;
      var_g = V     ;
      var_b = var_3 ;
    }
    else if ( var_i == 3 ) {
      var_r = var_1 ;
      var_g = var_2 ;
      var_b = V     ;
    }
    else if ( var_i == 4 ) {
      var_r = var_3 ;
      var_g = var_1 ;
      var_b = V     ;
    }
    else                   {
      var_r = V     ;
      var_g = var_1 ;
      var_b = var_2 ;
    }

    R = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
    G = (1-var_g) * 255;
    B = (1-var_b) * 255;
  }
}

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests