What you learn today
- Pi, nan, pinf, ninf and rgas
- Color., GasType., LogicType. at number positions
- Bare names only in their place
How many moles are in your tank? You need the gas constant for that. Which number is the colour orange? You do not have to know it by heart. The chip knows built-in constants and whole namespaces.
Built-in constants
| Name | Value | for |
|---|---|---|
pi | 3.14159… | circles, angles |
tau | 6.28318… | a full circle in radians |
deg2rad, rad2deg | degrees ↔ radians | sun angles |
rgas | 8.31446… J/(mol·K) | gas amounts |
pinf, ninf | plus and minus infinity | starting point for minimum and maximum searches |
nan | “not a number” | error value |
epsilon | smallest positive number | rarely useful |
rgas: moles from pressure
With pressure in kPa and volume in litres you compute moles directly: n = p · V / (R · T). One kPa times one litre is exactly one joule, the units fit.
define VOLUME 6000 # litres, small tank
alias mol r2
mul mol r0 VOLUME # r0 = pressure in kPa
div mol mol rgas
div mol mol r1 # r1 = temperature in K
Prefixed names
Wherever a number may stand, prefixed names work as well:
| Namespace | Examples |
|---|---|
Color. | Color.Green = 2, Color.Red = 4 |
DisplayMode. | DisplayMode.Celsius = 4, DisplayMode.Mol = 13 |
GasType. | GasType.Oxygen = 1, GasType.CarbonDioxide = 4 |
LogicType. | LogicType.Temperature = 6 |
Vent., Sound., PowerMode. … | come in the device lessons |
The prefix is relaxed about upper and lower case, the name behind it is not: Color.Red works, Color.red does not. A define may carry such a name too: define COLOUR_OK Color.Green.
Bare names only in their place
The chip only understands Temperature without a prefix where a LogicType is expected – that is, in l r0 d0 Temperature. At a number position the same bare name is an error:
move r0 Temperature # error
move r0 LogicType.Temperature # 6
The same goes for batch modes like Average: bare only at the very end of lbn.
nan directly at a value position, such as select r0 r1 nan r2, raises an error in the game. The workaround: define NAN nan and then use NAN.
Diagram
Exercise
Task
A mole calculator for the small tank (6000 litres): a pipe analyzer on the tank is attached to d0, an LED display to d1.
- The display shows the gas amount n = p · V / (R · T) in moles. Use the constant
rgas. - Display in mode
DisplayMode.Mol, colourColor.Orange– with names, not numbers. - Workshop style: define, alias, sections.
Hints
Hint 1
Read pressure and temperature from the analyzer with l.
Hint 2
mul mol press VOLUME, then two div: by rgas and by the temperature.
Hint 3
Mode and colour: s display Mode DisplayMode.Mol, s display Color Color.Orange.
Quiz
5 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in