このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


革命 Counting With Pascalite- plt1f HOME - - - - - - - - - Other 構成要素 for programmers - - - - - - - - - Pascalite Tutorial (米)棚上げする/(英)提議する of Contents

Pascal Tutorial: What has that hamster been up to?


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.

Most of the tutorials in this series come in 見解/翻訳/版s for Pascalite 使用者s, and for 使用者s with the FPC or TP Pascal compilers. This tutorial, sadly, cannot be 変えるd for the 非,不,無-Pascalite compilers. But keep reading through the end of this paragraph! The Pascalite has some built in 金物類/武器類 which isn't routinely 利用できる on the PCs used by the other compilers. 使用者s of those compilers should still read through this tutorial. There sill be some stuff that you can be a little relaxed about, but the important stuff should be obvious. Comments 特に for those 使用者s are 現在のd in the style you see in this paragraph.

"Why can't 非,不,無-Pascalite programmers do what is in this tutorial?", I hear you cry.

井戸/弁護士席... you could. But you either have to interface a 反対する to your PC, or you could use one of the "解雇する/砲火/射撃" inputs on the joystick interface, and de-bounce it and count pulses in ソフトウェア. Neither are really for the beginner, the likely reader of this tutorial. If you are not a beginner, and are happy to work in a higher language, e.g. Delphi or Java, then the way to go would be to attach a 1-Wire 反対する.

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 誤った.

(By the way... if you put something like this together with a real Pascalite, you may 遭遇(する) a problem arising from something called switch bounce. Don't worry that something is wrong with your 金物類/武器類 or your program if your system's count of wheel turns is too high. If you use a reed switch to sense the wheel's turning, the problem will probably go away, and if it doesn't try 追加するing "延期する(10);" just after the boItWas:=true; and if that doesn't 直す/買収する,八百長をする things email me!)

So! By now we (should!) have something that runs, and which flashes the LED on d0 whenever b0 goes from off to on. Not やめる what we were supposed to have, but we ARE getting there!

REPLACE the "pulse(d0,80);" with...
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.

Pascalite does have a few 制限s. For one thing, it isn't very clever about arithmetic, but that's 罰金... I'm all in 好意 of keeping things simple as long as they don't stop me getting where I want to go. In any 事例/患者, while talking about the way '一連の会議、交渉/完成する a problem, I can cover a 決定的な 概念.

In most Pascals, you could say something like..
bTurns:=(4+3)*5;
Once you know that the asterisk means multiply, I hope you can see that the above would 蓄える/店 35 in bTurns?

In Pascalite, you have to do things as follows:
bTurns:=4+3;
bTurns:=bTurns*5;
(FPC and TP are not as "stupid". They both 扱う bTurns:=(4+3)*5; just 罰金.)

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.

Returning ("At last...", did someone say?) to our hamster wheel 監視する: Look again at
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.

Don't forget: the "bTurns:=bTurns+1;" is part of the stuff that only happens "if boItWas=誤った and b0= true.... ", so don't be thinking bTurns will be made one bigger every time the program goes thought the repeat... until 宙返り飛行!

If you run the program now, you will no longer see flashes, but the number of turns will be 記録,記録的な/記録するd in bTurns. There's just one "slight difficulty": You can't SEE the number in bTurns!

Just after boItWas:=true; 追加する:
令状(portd,bTurns);
(On a Pascalite, what we've just seen would turn some of LEDs connected to the microcontroller on or off. 使用者s of FPC and TP who really, really don't care about binary numbers can stop reading here.)

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....

You can 変える any code, let's take 00001011 once you realize that each column in the code is 価値(がある) a 明確な/細部 量. Starting at the RIGHT 手渡す 味方する: The first column is 価値(がある) 1, the second 価値(がある) 2, the third 価値(がある) 4, the fourth 価値(がある) 8, and so on... the 価値(がある) (テニスなどの)ダブルス each time you go left one column. You ignore the column's 価値(がある) if there's a 0 in the column, you 追加する in the column's 価値(がある) if there's a 1 in the column. So, working from the 権利 of 00001011, that is 価値(がある) 1+2+8, it is 価値(がある) 11. Now look again at the third column of (警察などへの)密告,告訴(状) in the (米)棚上げする/(英)提議する above... see what it is 説? N.B. This is just ONE OF the binary codes that have been invented. It is SIMPLE binary numbers. We'll look at other ways of using 1's and 0's to say things later on. (Anything that says something with only two characters, e.g. 1 and 0, is a binary code. It is 極端に simplistic to speak of "binary" as if there's only one way of showing things with 1's and 0's.)

Find all of that just too tedious? How about a different system of showing on the LEDs how many counts there have been?

取って代わる the 令状(portd,bTurns); line with....
令状(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}
... etc
In 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)
Please also 公式文書,認める that I have two other 場所/位置s, and that the に引き続いて search will not 含む them. They have their own search buttons.

My Sheepdog Guides 場所/位置.
My Arunet 場所/位置.

Go to the 場所/位置s above, and use their search buttons if you want to search them.
To search this 場所/位置....

Search this 場所/位置 or the web 力/強力にするd by FreeFind

場所/位置 search Web search
The search engine 単に looks for the words you type, so....
*    (一定の)期間 them 適切に.
*    Don't bother with "How do I get rich?" That will 単に return pages with "how", "do", "I"....

You can also search this 場所/位置 without using forms.
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.


Want a 場所/位置 hosted, or email? You can also help me if you 調印する up 経由で this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their 顧客s. The Google advertisers 支払う/賃金 me. I know nothing about them or their services, of course.)



Valid HTML 4.01 Transitional Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!


Why does this page 原因(となる) a script to run? Because of the Google パネル盤s, and the code for the search button. Also, I have some of my pages' traffic 監視するd for me by eXTReMe tracker. They 申し込む/申し出 a 解放する/自由な tracker. If you want to try one, check out their 場所/位置. Why do I について言及する the script? Be sure you know all you need to about spyware.
Editor's Main Homepage
How to email or 令状 this page's editor, Tom Boyd

....... P a g e . . . E n d s .....