carlynorama

the blog

Last significant HL1606 update before the burn…

by Carlyn Maw on August 22, 2009, no comments

I can now get my LED lightstrip to play through a button-calibrated gradient.
 
In the video you can see I’m using an FSR in lieu of a piezo mic for testing. When the strip flashes green after the button press, the chip is taking a reading off the FSR to be the new gradientMax. When it goes red it means the values are higher than the system thinks is okay. You can set the last value of the gradient to be the same as the second to last if you don’t care. Same with the “off” state, easily side stepped. Again the whole code is a little long to post here, but here’s some of the new stuff.

// ----- some stuff from the setup  colorArray[0] = B10000000; // Dark  colorArray[1] = B10100001; // Pink Red colorArray[2] = B10000001; // Red Red  colorArray[3] = B10000101; // Yellow  colorArray[4] = B10000100; // Green  colorArray[5] = B10010000; // Blue  colorArray[6] = B10010100; // Turquoise  colorArray[7] = B10010001; // Purple  colorArray[8] = B10010101; // White   //gradient  gradientArray[0] = 0; // what gradient does if sensor is out of bounds too low   // set this to the same as the one after it if you don't care  gradientArray[1] = 8;  gradientArray[2] = 6;  gradientArray[3] = 5;  gradientArray[4] = 2; //what gradient does if sensor is out of bounds too high   //set this to the same color as the one before it if you   //don't care. // ---- end in setup  //---- partial main loop  gradientLineLevel = analogRead(sensorPin); // get a reading from the fsr  gradientNum = getGradientLevel(gradientLineLevel); // get what gradient segment you are  //in the future could run case statements that have light patterns  doColor(gradientArray[gradientNum], 20); // low duration, more responsive system.  //my version of doColor looks a lot like the doNote function is some previous code  //but without the "white space" at the end of it. //---- end of some of the stuff in main loop  byte getGradientLevel(int myLineLevel) {  int s;   if (myLineLevel > gradientMax) {   return (gradientArrayLength-1);  }  if (myLineLevel < gradientMin) {   return 0;  }    for (s = 1; s <= (gradientArrayLength-2); s++) {   int myMin = gradientMin + (s-1)*gradientSteps;   int myMax = gradientMin + (s)*gradientSteps;    // covers the extra little slop so I don't have to deal with   // making gradientSteps a float   if (s == (gradientArrayLength)) {   myMax = gradientMax;   }    // range hit   if (myLineLevel >= myMin && myLineLevel <= myMax) {   return s;   } }   // if it made it through the for loop with no hits, out of bounds exception  // should really never get here b/c of if statements at top of function  return 0;  }  void setGradientRange() {  gradientMax = analogRead(sensorPin);  gradientRange = gradientMax - gradientMin;  // gradient steps uses gradientArrayLength-1 as the divisor  //because gA[0] is the out of bounds exception  //gA[last] is the upper out of bounds exception  gradientSteps = gradientRange/(gradientArrayLength-2); }