Hiya,
Long time no code!
I'm wanting to use Mike, K8LH 'Just Basic' code to generate values towards linerarizing an LED for PWM ...what Mike has done is great & & more or less ideal for my needs, but to save a bit of post editing for use with my PIC of choice, I ideally seek a way of having the code place a DW on the front of every line.
Mike wrote it in standard basic, but I'm not familiar with syntax (besides I'm very rusty with coding now!) & hoped that someone could quickly edit the code to place a DW at the front of all the outputted lines.
Here's Mike's code that I've modified a little already...
Code:
' Maxim Gamma Correction Algorithm
'
' JustBASIC (free) interpreter
'
Input "Gamma array size: "; arraysize
Input " Total PWM steps: "; width
Input "Gamma correction: "; gamma ' maxim uses 2.5
FOR index = 0 to arraysize-1
dcyval = INT(width*(((width/arraysize*(index+1))/width)^gamma))
if(index = 0) then
PRINT
else
if(index MOD 34 = 0) then 'this dictates how many values per line
PRINT " " 'this puts no comma at the end of the line
else
PRINT ","; 'this puts commas in between the values
end if
end if
if(dcyval < 100) then print " ";
if(dcyval < 10) then print " ";
PRINT dcyval;
NEXT index
PRINT
REM CLOSE
The above gernerates output like this
Code:
Gamma array size: 255
Total PWM steps: 1023
Gamma correction: 2
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
19, 20, 21, 22, 23, 25, 26, 27, 29, 30, 31, 33, 34, 36, 37, 39, 40, 42, 44, 45, 47, 49, 51, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72
74, 77, 79, 81, 83, 86, 88, 90, 93, 95, 98,100,103,105,108,111,113,116,119,121,124,127,130,133,136,139,141,144,148,151,154,157,160,163
166,170,173,176,180,183,186,190,193,197,200,204,208,211,215,219,222,226,230,234,238,241,245,249,253,257,261,265,269,274,278,282,286,290
295,299,303,308,312,317,321,326,330,335,339,344,349,353,358,363,368,373,377,382,387,392,397,402,407,412,417,423,428,433,438,444,449,454
460,465,470,476,481,487,492,498,504,509,515,521,526,532,538,544,550,556,561,567,573,579,586,592,598,604,610,616,623,629,635,641,648,654
661,667,674,680,687,693,700,707,713,720,727,734,740,747,754,761,768,775,782,789,796,803,810,817,825,832,839,846,854,861,868,876,883,891
898,906,913,921,928,936,944,952,959,967,975,983,991,999,1007,1014,1023
whereas what I seek is a DW at the front of each line like thus...
Code:
Gamma array size: 255
Total PWM steps: 1023
Gamma correction: 2
DW 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
DW 19, 20, 21, 22, 23, 25, 26, 27, 29, 30, 31, 33, 34, 36, 37, 39, 40, 42, 44, 45, 47, 49, 51, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72
DW 74, 77, 79, 81, 83, 86, 88, 90, 93, 95, 98,100,103,105,108,111,113,116,119,121,124,127,130,133,136,139,141,144,148,151,154,157,160,163
DW 166,170,173,176,180,183,186,190,193,197,200,204,208,211,215,219,222,226,230,234,238,241,245,249,253,257,261,265,269,274,278,282,286,290
DW 295,299,303,308,312,317,321,326,330,335,339,344,349,353,358,363,368,373,377,382,387,392,397,402,407,412,417,423,428,433,438,444,449,454
DW 460,465,470,476,481,487,492,498,504,509,515,521,526,532,538,544,550,556,561,567,573,579,586,592,598,604,610,616,623,629,635,641,648,654
DW 661,667,674,680,687,693,700,707,713,720,727,734,740,747,754,761,768,775,782,789,796,803,810,817,825,832,839,846,854,861,868,876,883,891
DW 898,906,913,921,928,936,944,952,959,967,975,983,991,999,1007,1014,1023
Can anyone help me out here?
(the code runs with this http://www.justbasic.com/download.html )
Bookmarks