User manual

64
GPIO.setmode(GPIO.BCM)
LED = [4,18,23]
for i in range(3):
GPIO.setup(LED[i], GPIO.OUT, initial=False)
A list defines the GPIO port numbers of the three LEDs. The loop initializes the three GPIO ports as outputs
and resets all LEDs to its off-state.
Also in this experiment, we use the construct
try...exceptand an infinity loop to automatically run the
programme over and over until it stopped by the user with
[Ctrl]+[C] ]. Now the really interesting functions
follow which will access the operating system and check for the free space.
s = os.statvfs('/') The statistics module os.statvfs() from the library os provides various statistical
information about the file system, which are rewritten as an object in the variable
s at each loop run within
the infinity loop.
f = s.f_bsize * s.f_bavail / 1048576 Now method s.f_bsize delivers the size of the memory space
block in byte.
s.f_bavail shows the number of free blocks. The product of the two values is therefore the
number of free bytes, divided here by 1,048,576 to get the number of free megabytes. The result is stored in
the variable
f.
if f < g1:
x = "100"
The free space is smaller than the first limit value (1 MB), the string sequence x, which indicates the pattern
of turned on LEDs, is set to
"100". The first, the red LED, will light up. The pattern is a simple string
containing the digits 0 and 1.
elif f < g2:
x = "110"
elif f < g3:
x = "010"
elif f < g4:
x = "011"
By means of the elif queries the other limits are queried and the LED pattern is set accordingly, if the first
query is not valid, that is, there is more than 1 MB of free disk space.
else:
x = "001"
If none of the queries are true, that is, there is more free disk space than the highest limit, the LED pattern is
set to
"001". The last, the green LED should light up.
for i in range(3):
GPIO.output(LED[i], int(x[i]))
A loop defines the GPIO output values for the three LEDs. The numerical value of the digit in question from
the string
0 or 1is assigned to all LEDs in succession. The values 0 und 1can be used like False or True to