このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
This tutorial covers some more important ground regarding the use of simple variables. It also tells you a little more about binary numbers, but the binary number stuff is optional! The program will be something 奮起させるd by a 地位,任命する in the internet newsletter 生成するd by 熱中している人s for the Dallas (aka Dalsemi, aka Maxim) 1-Wire / iButton / MicroLan 製品 as 適用するd to 天候 監視するing. He wired his children's hamster's 演習 wheel to a computer so that the family could see a graph of how active Spike was, 24x7. Spike, like all of his 種類, was a night フクロウ, busy the night, which the children had not known.
With a Pascalite, all it took was a reed switch (not 複雑にするd). 効果的に, each time the wheel went '一連の会議、交渉/完成する, a switch was turned on for a moment, and then off again. If you have a real Pascalite, you can wire a doorbell-type switch to b0, but the 事実上の Pascalite will work 罰金, too... you'll just have the minor annoyance of having to turn the switch on AND THEN OFF again to ふりをする each turn of the wheel. (For 前進するd readers: Yes, the Pascalite does have a 反対する, it might be a better way to 監視する a stream of pulses. Remember this tutorial is introductory!)
以前, I've just given you the final code for a program. This time, I'm going to take you through the steps I would use in 令状ing something. Notice how, for example, when I type a "begin", I すぐに type the corresponding "end", and THEN I go 支援する and fill in what goes in between. Pascal's design makes it 平易な to work like this, and doing so helps you keep 跡をつける of what you're up to. This will be a little strange for you, because you don't know where I'm going... but after you've been through the 演習 and しっかり掴む where we've arrived, go 支援する, look at the 開発 sequence again, and I think you'll see why I went from nothing to finished program 経由で the 大勝する I took. At each 行う/開催する/段階 below, I'll 示す which lines are newly 追加するd. After each 行う/開催する/段階, you should be able to "run" the program without errors. I've put "run" in 引用するs because the program won't 現実に do very much, but you should at least get not (民事の)告訴s when you try to run it. this is another advantage of building the program up as I am 論証するing.... you can keep it "working" 権利 from the start, and if you re-"run" it after each 段階 of the building 過程, if there are errors, you've only 追加するd a little new stuff since the last time the program was running, so the problems only have a small area in which to hide. Start by entering the に引き続いて:
program Spike; begin end.宣言する the variables we need...
program Spike; var boItIs, boItWas: boolean; {new} bTurns:byte;{new} begin end.Initialize a few things and put in the 宙返り飛行 to make the main part of the program continue 無期限に/不明確に. Previous Pascalite tutorials explained that the def_out line 簡単に alters settings in the Pascalite's electronics so that the 明示するd pins can be used for 生産(高). The line bTurns:=0 should be read "bTurns becomes 無". In other words, the 影響 of that line is to 蓄える/店 the number 無 in the variable 指名するd bTurns. 結局, we will have the number of turns the wheel has made 蓄える/店d in bTurns.
program Spike; var boItIs, boItWas: boolean; bTurns:byte; begin def_out(d0,d1,d2,d3,d4,d5,d6,d6,d7); {new} bTurns:=0; {new} boItWas:=b0; {new} repeat {new} until 4=5; {new} end.追加する an if... then... that will watch to see if the switch 大(公)使館員d to b0 is in the off position. (There is no "else..." part this time.)(This is a LITTLE different from the 類似の thing we did in an earlier tutorial. We're going to mostly ignore the change from on to off, only counting off to ons... but we need to keep boItWas up to date. Remember: b0 will "boil 負かす/撃墜する to" 誤った if the switch 大(公)使館員d to b0 is in the off position.)
program Spike; var boItIs, boItWas: boolean; bTurns:byte; begin def_out(d0,d1,d2,d3,d4,d5,d6,d6); bTurns:=0; boItWas:=b0; repeat if not(b0) then boItWas:=誤った;{new} until 4=5; end.Now 追加する something so that when b0 goes to true, the LED on d0 flashes 簡潔に. We won't have this "flash 簡潔に" in the final 見解/翻訳/版 of the program, but we're 令状ing it in at this 行う/開催する/段階 as a little 実験(する) of what we think we've 達成するd.
program Spike; var boItWas: boolean; bTurns:byte; begin def_out(d0,d1,d2,d3,d4,d5,d6,d6); bTurns:=0; boItWas:=b0; repeat if not(b0) then boItWas:=誤った; if not(boItWas) and b0 then begin{this.... and partner below:FIRST new} pulse(d0,80);{later new} boItWas:=true;{later new} end;{this.... and partner above:FIRST new} until 4=5; end.Think about what boItWas is 存在 used for. We don't want a flash on d0 every time we go through the 宙返り飛行 and find b0 true... just on the first time through the 宙返り飛行 when we find it true when PREVIOUSLY it was 誤った.
bTurns:=bTurns+1;We need to digress to talk about arithmetic with variables. It is perfectly okay to say something like bTurns:=4+3; (although that would be of no use to us in counting hamster wheel turns) If you said bTurns:=4+3, you would be 説 bTurns becomes 7, i.e., put the number 7 in the variable called bTurns. 4+3 "boils 負かす/撃墜する" to 7.
bTurns:=(4+3)*5;Once you know that the asterisk means multiply, I hope you can see that the above would 蓄える/店 35 in bTurns?
bTurns:=4+3; bTurns:=bTurns*5;
I hope you're remembering to think of ":=" as "becomes", because if you're looking at the line above and seeing "bTurns equals bTurns times 5" you're going to be 混乱させるd!! How can anything equal itself times 5 ?!?!? (Of course, infinity times five does equal infinity, but that is a rather special exception.)
No. "bTurns:=...." means that you want the number 蓄える/店d in bTurns to change to a new number. When we said bTurns:=0, I hope you were happy? What we're doing now isn't a lot more 複雑にするd.... though it is at the heart of that lesson Per Ranhoff gave so long ago. We are 説 with the "....bTurns*5" (権利 手渡す 味方する of 表現) is, "Look in the variable called bTurns. What number do you find there? Multiply that number times 5." So- if bTurns 以前 held seven then "bTurns times five" boils 負かす/撃墜する to 35. Keep the "boils 負かす/撃墜する to" number in your 長,率いる for just a moment. Forget where it (機の)カム from. Look again at the first part of "bTurns:=...". That says "the contents of the variable bTurns BECOMES..."... so- the number 蓄える/店d in bTurns changes to whatever number the 権利 手渡す 味方する of the 声明 boiled 負かす/撃墜する to.bTurns:=bTurns+1;権利 at the start of the program, with "bTurns:=0;" we said "put 無 in the variable called bTurns. the first time the program does "bTurns:=bTurns+1;", what's in bTurns will be changed to 1. When the program has been running for a while, you'll reach a time when bTurns 持つ/拘留するs 15. At that 行う/開催する/段階, "bTurns+1" will boil 負かす/撃墜する to 16, and the number in bTurns will become 16. And so on.
令状(portd,bTurns);
Now anyone who knows about simple binary numbers can see how many times the switch has been switched on by looking at the LEDs of port B. If no LEDs are on, it hasn't been switched on once... we're going to say "there have been no counts" to say that. If just the 権利 手渡す LED is on, there has been one count. In the に引き続いて, "1" means the LED is on, "0" means the LED is off. For the moment, ignore the 権利 手渡す column
What the pattern LEDs / Count / stands for... 00000000 0 00000001 1 00000010 2 00000011 3 2+1 00000100 4 00000101 5 4+1 00000110 6 4+2 00000111 7 4+2+1 00001000 8 00001001 9 8+1 00001010 10 8+2 00001011 11 8+2+1 00001100 12 8+4 00001101 13 8+4+1 00001110 14 8+4+2 00001111 15 8+4+2+1 00001000 16 00001001 17 16+1 00001010 18 16+2 ... and so on.....There is a pattern to the codes for 0,1,2,3,4....
令状(portd,0);{Turns all the LEDs off} if bTurns>4 then 令状(portd,128); if bTurns>9 then 令状(portd,192);{128+64} if bTurns>14 then 令状(portd,224);{128+64+32} if bTurns>19 then 令状(portd,240);{128+64+32+16} if bTurns>24 then 令状(portd,248);{128+64+32+16+8} ... etcIn this 見解/翻訳/版 of the program, you'll get no LEDs on until there have been 5 turns, the left 手渡す one on after 10 turns, the left 2 on after 15 turns, etc. This isn't the most elegant way to do the 職業, but it is pretty (疑いを)晴らす, I hope. (Admittedly, getting the 権利 number for the 令状(portb... 声明 is a bit hard, but you could always 令状 out a 十分な (米)棚上げする/(英)提議する of numbers vs codes if you had to. Many Pascals, maybe even Pascalite, have ways to let you 令状 a number in binary, in which 事例/患者 the numbers for the lines above would have been 10000000, 11000000, 11100000, 11110000, 11111000, etc)
|
Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.
....... P a g e . . . E n d s .....