This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
built_in:sensors [2014/09/17 19:18] stevegarman created |
built_in:sensors [2018/01/03 10:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | ===== Create | + | |
- | Create Sensor objects using the CreateSensor function of the app object: | + | // |
+ | |||
+ | ===== Description | ||
+ | Create Sensor objects using the **CreateSensor** function of the **[[built_in: | ||
< | < | ||
- | Types available are: "Accelerometer", | + | Types available are: |
+ | * **Accelerometer** | ||
+ | * **MagneticField** | ||
+ | * **Orientation** | ||
+ | * **Light** | ||
+ | * **Proximity** | ||
+ | * **Temperature** | ||
+ | * **GameRotation** | ||
+ | * **GeomagneticRotation** | ||
+ | * **Gravity** | ||
+ | * **Gyroscope** | ||
+ | * **HeartRate** | ||
+ | * **Acceleration** | ||
+ | * **Pressure** | ||
+ | * **Humidity** | ||
+ | * **Rotation** | ||
+ | * **Motion** | ||
+ | * **StepCounter** | ||
+ | * **StepDetector** | ||
+ | |||
+ | Try **sns.GetNames()** which lists all the sensor information. You can probably scan for certain keywords. | ||
+ | |||
+ | You can also use a sensor id number instead of the name (just in case a future sensor is added). | ||
+ | |||
+ | You can use the **SetOnChange** function of the Sensor to set the name of a function you want to be called when a the changes occur. | ||
+ | |||
+ | Change the rate that a sensor checks for changes by adding one the options **"Fastest" | ||
+ | "Slow" | ||
- | You can use the SetOnChange function of the Sensor to set the name of a function you want to be called when a the changes occur. | ||
- | Change the rate that a sensor checks for changes by adding one the options " | ||
===== Methods ===== | ===== Methods ===== | ||
- | ^Method ^Description ^ | + | Some controls use the same methods.\\ |
- | |sns.GetAzimuth| | | + | For examples of the **[[same methods]]** look here. |
- | |sns.GetHeight| | | + | ^ Method |
- | |sns.GetPitch| | | + | | Sensor.GetAzimuth() | | |
- | |sns.GetRoll| | | + | | Sensor.GetHeight() |
- | |sns.GetVisibility| | | + | | Sensor.GetNames() |
- | |sns.GetWidth| | | + | | Sensor.GetPitch() |
- | |sns.Release| | | + | | Sensor.GetRoll() |
- | |sns.SetBackColor| | | + | | Sensor.GetType() |
- | |sns.SetBackGradient| | | + | | Sensor.GetValues() |
- | |sns.SetBackGradientRadial| | | + | | Sensor.SetMaxRate( rate ) | default 20ms | |
- | |sns.SetBackground| | | + | | Sensor.SetMinChange( value ) |
- | |sns.SetMargins| | | + | | Sensor.SetOnChange( callback ) |
- | |sns.SetMinChange| | | + | | Sensor.Start() |
- | |sns.SetOnChange| | | + | | Sensor.Stop() |
- | |sns.SetPadding| | | + | |
- | |sns.SetPosition| | + | ===== Examples ===== |
- | |sns.SetSize| | | + | ^Sensor Type ^Code Example ^ |
- | |sns.SetVisibility| | | + | |Accelerometer | <code javascript> |
- | |sns.Start| | | + | { |
- | |sns.Stop| | | + | lay = app.CreateLayout( " |
+ | |||
+ | txt = app.CreateText( "", | ||
+ | lay.AddChild( txt ); | ||
+ | app.AddLayout( lay ); | ||
+ | |||
+ | | ||
+ | sns.SetOnChange( sns_OnChange ); | ||
+ | sns.Start(); | ||
+ | |||
+ | } | ||
+ | |||
+ | function sns_OnChange( x, y, z, time ) | ||
+ | { | ||
+ | txt.SetText( " | ||
+ | } | ||
+ | </ | ||
+ | |Orientation | <code javascript> | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | txt = app.CreateText( "", | ||
+ | lay.AddChild( txt ); | ||
+ | app.AddLayout( lay ); | ||
+ | |||
+ | | ||
+ | sns.SetOnChange( sns_OnChange ); | ||
+ | sns.Start(); | ||
+ | |||
+ | } | ||
+ | |||
+ | function sns_OnChange( azimuth, pitch, roll, time ) | ||
+ | { | ||
+ | var msg = " azimuth = " + azimuth.toFixed(1); | ||
+ | msg += "\n pitch = " + pitch.toFixed(1); | ||
+ | msg += "\n roll = " + roll.toFixed(1); | ||
+ | txt.SetText( msg ); | ||
+ | } | ||
+ | </ | ||
+ | |Light | <code javascript> | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | txt = app.CreateText( "", | ||
+ | lay.AddChild( txt ); | ||
+ | app.AddLayout( lay ); | ||
+ | |||
+ | | ||
+ | sns.SetOnChange( sns_OnChange ); | ||
+ | sns.Start(); | ||
+ | |||
+ | } | ||
+ | |||
+ | function sns_OnChange( lux ) | ||
+ | { | ||
+ | txt.SetText( "level = " + lux + " lux" ); | ||
+ | } | ||
+ | |||
+ | </ |