You are currently viewing a search engine-friendly (archive) version of this page.
View Full Version : Pascal Resistor Colour Code
Immy
June 20, 2001, 02:53 pm
Hey guys!
can anyone help me to write a program in TurboPascal. i want the program to take in as input the colour codes of resistors, and then outputs the value of these resistors.
thanx
Immy
------------------
MikeFoster
June 20, 2001, 05:14 pm
Hi Immy, welcome to the board!
There are some really good programmers here - so I'm sure you'll get some good feedback. HTML is disabled in this forum, but you can use the "CODE" UBB tag (put it in square brackets) - it makes it look like this:
void compress(char far* buffer)
{
char data, i, mask;
unsigned bofs = 0, end_of_scrn = 160 * (LastRow + 1);
while(bofs < end_of_scrn) {
data = 0;
mask = 1;
for(i = 0; i < 8; ++i, bofs += 2) {
if(*(video_vector + bofs) == AliveCell)
data |= mask;
mask <<= 1;
}
*buffer++ = data;
}
}
Click the edit icon on this post to see how I used it here.
If you already have some code written, feel free to post it - we'll tear it apart! http://www.helpfromtechs.com/ubb/smilies/lol.gif
------------------
Help From Techs Support Forums
Immy
June 20, 2001, 05:49 pm
Hey there Mike!
thanx for your welcome, and your note on HTML. i hope someone can help me with my program.
i dont actually have any codes written, i have on just 'entered' the worls of PASCAL!
~~~Immy~~~
------------------
MikeFoster
June 20, 2001, 08:19 pm
Immy,
Where to start depends on your experience. Have you programmed with other languages? If this is the first, that's fine - Pascal is a good one to start with.
(1) Start thinking (and writing down) exactly what data can be input, what data can be output and what kind of internal data (for calculations) you will need.
(2) Next, if you've used arrays or records (structures) before, then start thinking about how you will structure (store) each of the different classes of data.
(3) At the same time, think about what operations will need to be performed on the data. This should influence the decision of how to "store" the data.
You may be way ahead of me, I don't know... but I was just thinking about it and thought I'd chat a little.
cya!
------------------
Help From Techs Support Forums
MikeFoster
June 23, 2001, 04:36 am
Woa! Look at this:
http://www.dannyg.com/javascript/res/resload.htm
------------------
Help From Techs Support Forums
Immy
June 23, 2001, 11:27 am
hi there!
thanks for the link Mike. it wont help me with my program, but it will come in use for my Electronics Course.
cheerz!
~~~Immy~~~
------------------
Immy
July 3, 2001, 05:12 pm
hi there!
i have written the program. i just wonderd if anyone would like to look at it if i post it on here, to see if you can improve it.
laterz
Immy
------------------
MikeFoster
July 3, 2001, 07:06 pm
Hi Immy,
I don't have a Pascal compiler anymore but I'd be glad to look at it http://www.helpfromtechs.com/ubb/smilies/smile.gif
------------------
Help From Techs Support Forums
Immy
July 3, 2001, 08:05 pm
hi there!
i have written the program. i was just wondering if someone could check it if i posted it on here, to make it better.
thanx,laterz
Immy
------------------
Immy
July 4, 2001, 07:05 pm
hi there!
here you go.....my program....
PROGRAM res_value;
uses crt;
TYPE
colour_codes = ARRAY[0..9] of string;
CONST
noughts = '0000000000';
VAR
Read_value: FILE OF STRING;
Colour : Colour_codes;
count : Integer;
error1 : Char;
error2 : Char;
error3 : Char;
pause_done: Char;
first_band: String;
sec_band : String;
third_band: String;
fourth_band: String;
Output_string: String;
Output_string2: String;
Ohms : String;
Ohms_long : Integer;
procedure finishing_screen;
begin
end;
procedure print_out_answers;
begin
end;
procedure work_out_values;
begin
IF (pause_done = #66) OR (pause_done = #98) THEN
begin
For count:= 0 To 9 Do
IF first_band = colour[count] Then
begin
STR(count,Output_string);
End;
writeln (Output_string);
For count:= 0 To 9 DO
IF sec_band = colour[count] THEN
begin
STR(count,Output_string2);
Output_string:= Output_string + Output_string2;
end;
writeln(Output_string);
For count:= 0 To 9 DO
IF third_band = colour[count] Then
begin
Output_string2 := Copy(noughts,1,count);
Output_string:= Output_string + Output_string2;
writeln(Output_string);
end;
end;
end;
procedure value_to_colour;
begin
writeln ('value to colour:');
writeln('Please type in a resistance value');
writeln('in ohms to convert');
REPEAT
error1 := 'N';
error2 := 'N';
error3 := 'N';
READLN (ohms);
first_band := COPY (ohms,1,1);
sec_band := COPY (ohms,2,1);
third_band := COPY (ohms,3,1);
IF (first_band > #48) AND
(first_band < #57) THEN
begin
writeln ('First character accepted');
error1:= 'N';
end
ELSE
Begin
writeln ('Invalid first character');
error1 := 'Y';
End;
IF (sec_band > #48) AND
(sec_band < #57) THEN
begin
writeln ('Second character accepted');
error1:= 'N';
end
ELSE
Begin
writeln ('Invalid Second character');
error1 := 'Y';
End;
Ohms_long := Length (ohms);
IF Ohms_long > 2 THEN
begin
FOR count := 2 to Ohms_long Do
IF COPY(Ohms,count,1) <> #48 THEN
begin
writeln ('Invalid characters within zeros');
error1 := 'Y';
end;
end;
UNTIL (error1 = 'N');
end;
procedure colour_to_value;
begin
REPEAT
writeln (' The valid colours are : ');
FOR count := 0 to 9 DO
begin
writeln (colour[count]);
end;
writeln('Colour to value');
writeln('what is the colour of the first band?');
readln(first_band);
writeln('what is the colour of the second band?');
readln(sec_band);
writeln('what is the colour of the third band?');
readln(third_band);
error1 := 'Y';
error2 := 'Y';
error3 := 'Y';
FOR count := 0 To 9 Do
begin
IF colour[count] = first_band Then error1 := 'N';
end;
IF error1 = 'Y' THEN
begin
writeln ('First band colour is invalid');
end;
FOR count := 0 To 9 Do
begin
IF colour[count] = sec_band Then error2 := 'N';
end;
IF error2 = 'Y' THEN
begin
writeln ('second band colour is invalid');
end;
FOR count := 0 To 9 Do
begin
IF colour[count] = third_band Then error3 := 'N';
end;
IF error3 = 'Y' THEN
begin
writeln ('third band colour is invalid');
end;
UNTIL (error1 = 'N') AND (error2 = 'N') AND (error3 = 'N');
end;
procedure take_in_values;
BEGIN
REPEAT
clrscr;
TextColor(Yellow);
writeln('***************************************** *****');
writeln;
TextColor(White);
writeln(' (a) Convert From Value To Colour ');
writeln;
writeln(' (b) Convert From Colour To Value ');
writeln;
writeln(' INPUT A OR B ');
TextColor(Yellow);
writeln('***************************************** *****');
pause_done := READKEY;
UNTIL (pause_done = #65) OR (pause_done = #66) OR (pause_done = #97) OR (pause_done = #98);
IF (pause_done = #65) OR (pause_done = #97) THEN
begin
value_to_colour;
end;
IF (pause_done = #66) OR (pause_done = #98) THEN
begin
colour_to_value;
end;
end;
PROCEDURE opening_screen;
BEGIN
REPEAT
clrscr;
TextColor(Yellow);
writeln('***************************************** *****');
writeln;
TextColor(White);
writeln(' **** RESISTOR COLOUR CODE PROGRAM **** ');
writeln;
writeln(' PRESS SPACEBAR FOR MAIN MENU ');
writeln;
TextColor(Yellow);
writeln('***************************************** *****');
pause_done := READKEY
UNTIL pause_done=#32
END;
PROCEDURE starting_values;
BEGIN
ASSIGN (Read_value, 'A:values.txt');
RESET (Read_value);
FOR count:= 0 TO 9 DO
BEGIN
READ(Read_value,colour[count]);
END;
CLOSE(Read_value);
FOR count:= 0 To 9 DO
BEGIN
writeln('Colour ',count,' is ',colour[count]);
END;
END;
BEGIN
clrscr;
starting_values;
Opening_screen;
take_in_values;
work_out_values;
print_out_answers;
finishing_screen;
END.
cheerz!
Immy
------------------
vBulletin Copyright © Jelsoft Enterprises Ltd., 2000-2009.