Line: 1 to 1 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Sensors for IoT devices or A virtual world reflecting the real world | |||||||||||
Line: 240 to 240 | |||||||||||
![]() | |||||||||||
Changed: | |||||||||||
< < | The same thing as a script in idle | ||||||||||
> > | The same thing as a script in idle | ||||||||||
Here you see the 2 idle windows. | |||||||||||
Line: 289 to 289 | |||||||||||
![]() | |||||||||||
Changed: | |||||||||||
< < | As you can see, there are no braces around the conditional block but it is indented # indicates an comment In addition to the if statement above we have elif and else | ||||||||||
> > | As you can see, there are no braces around the conditional block but it is indented # indicates an comment In addition to the if statement above we have elif and else | ||||||||||
while loop | |||||||||||
Line: 300 to 304 | |||||||||||
![]() | |||||||||||
Changed: | |||||||||||
< < | This program uses multiple assignments a,b are assigned in the same line Again you can see that the block starts with : and is indented. | ||||||||||
> > | This program uses multiple assignments a,b are assigned in the same line Again you can see that the block starts with : and is indented. | ||||||||||
Lists | |||||||||||
Line: 382 to 388 | |||||||||||
![]() | |||||||||||
Added: | |||||||||||
> > | Calling functions from a ModuleThis is how we call a function (method) from a module.![]() ![]() Executing ModulesOften modules contain only function or class (see later) definitions However it is also possible to include the function calls (the main routine) into the module e.g. to demonstrate how the functions are to be used. In this case the name of the module changes to __main__We can therefore find out if the module is imported or executed by checking the name variable: if __name__ == "__main__" this executes the main code only if not imported into a main program Command Line ArgumentsPrograms can be called with arguments. When calling an editor you my give the name of the file to be edited as an argument. There may also be options that are passed as arguments, e.g. ls -ls $HOME These arguments can be read (as strings) in Python:![]() maxFib=int(argv[1])
Running the module with args![]() FilesIn order to read of write a file it must first be opened: f = open(filename,w) After which you can write the file. In read mode, the w must be replaced by r![]() ClassesIn object oriented programming languages you can define classes encapsulating data and functions (methods in the oo jargon) that act on these data. You can create sub-classes having most of the properties of the base class but provide more data and/or methods or some of the methods are modified (overridden). This is called inheritance. Python implements these features. While in many object oriented languages we distinguish between public and private data, in Python all data are public. A convention is to precede a variable name with an _ if it is not intended for use external to the class.---+++ Creating ClassesThe syntax for creation of classes is similar to functions![]() i is an instance variable f is a method You may define a method with name __init__which is called when the instance object of the class is created (in the above example: mc = MyClass () The short description of the class can be found in the instance variable _ _doc__ Classes and the SensorsAs classes describe real world objects they are particularly using for describing our sensors Connection details, calibration parameters etc. can be described in the instance variables Actions of the sensors like triggering, readout etc. are implemented in methods.Instance initializationThere is a special method named _ _init__ which is called when the instance of a class is created. This method allows to
A Class Implementation realizing a simple Calculator![]() A Sensor Demo![]() The cobbler PinOut![]() The SensorsThis is the idea: The hardware includes:
The sensors in the virtual worldWe see the distance sensor in front and the color sensor with its LEDs switched off, in the backThe (white) paper sheet is in frontof the distance sensor The red ball is the center of the coordinate system ![]() | ||||||||||
%SLIDESHOWEND%
-- ![]() | |||||||||||
Line: 426 to 591 | |||||||||||
| |||||||||||
Added: | |||||||||||
> > |
|