// ----- 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 mail 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); }
No comments:
Post a Comment