Just wondering if any of the C ppl here can tell me of a way to be able to use Case in C with multiple values so I can type less.
e.g. Sudeo code in PB We can do something like:
ADCValue[channel_number]=ADRESH;
switch (ADCValue[0]){
Case 130: Case 131: Case 132: Case 133: Case 134: Case 135: Case 136: Case 137:
Case 138: Case 139: Case 140: Case 141: Case 142: Case 143: Case 144: Case 145: //4k7
Return 1;
Break;
Case 175: Case 176: Case 177: Case 178:Case 179: Case 180: Case 185: Case 186: Case 187:
Case 188: Case 189: Case 190: Case 191: Case 192: Case 193: Case 194: Case 195: //6k8
Return 2;
Break;
};
So just wondering if any1 knows a way to use any similar 'To' statement in C something like the way it works in PB?
Thanks Fred.
Currently I have used 8 bits of a 10 bit resolution ADC converter by dropping the 2 low order bits in the function register, so I might see if I can do a little bitshifting on my left over high order bits to turn my resolution down from 8 bits to 6 also which might make my coding a little easier to work with & hopefully should keep within my desired needs with this project.
Perkin wrote:@Baldrick
Did you realise that the check for 181->184 is missing in the C version?
No matter Perkin, it is only a rough seudo code pulled from a microcontroller project & quickly even more roughed up in the PB editor to try & help explain what I would have liked to do with the C code.
Guess I am just made a little lazy by the ease of PB these days....
if (ADCValue[0]>=130 && ADCValue[0]<=145) {
Return 1;
}
AIR.
That certainly looks like a good way to simplify things for me. I will give it a go. I have a reasonably stable proto board working now, which I will recode completely soon & will try this in the new code.
fwiw, I just simply bitshifted my analogue to digital resolution down to 6 bits which has worked wonders also.
It is just a pity that we cannot do some of the neat little tricks in C such as the Case X to Y thing which works so well for me in PB..
lol, np. In my situation I have stuck with using the switch case routine & currently I have moved forward enough to be at a stage where I am now in the process of getting a 1st run prototype production of my micrcocontroller pcb's manufactured. So it's all good.
Most C compilers (and Pascal, etc) can only use a constant as a case.
Therefore any complex conditions to share a few case statements needs
a prior function to convert conditions to a constant.
If you think of "switch" like a rotary switch, it helps to overcome
the despair of being unable to condense the source code lines.