This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:itt:servo [2018/12/06 06:31] – rim.puks | en:iot-open:remotelab:itt:servo [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Servo module ===== | + | ===== ITT Servo module ===== |
| This laboratory is located in the office of ITT Group in Tallinn, Estonia. | This laboratory is located in the office of ITT Group in Tallinn, Estonia. | ||
| Line 41: | Line 41: | ||
| ==== Hands-on labs ==== | ==== Hands-on labs ==== | ||
| - | //List study scenarios | + | |
| - | | + | === Example code === |
| - | | + | |
| - | | + | <code c> |
| - | | + | /* |
| - | Note, assume that more professional group automatically contains less professional ones. Note - use language and as appropriate to the target group, i.e.:// | + | * IoT Servo example |
| - | < | + | * |
| - | | + | * This example subscribe to the " |
| - | | + | * change servo position |
| - | | + | * |
| + | * Created 11 Sept 2017 by Heiko Pikner | ||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | //Pin definition for the Servo (D3) | ||
| + | #define SERVO_PIN | ||
| + | |||
| + | Servo myservo; | ||
| + | |||
| + | // Change | ||
| + | // mosquitto_pub | ||
| + | // = this calls servo motor to change position | ||
| + | |||
| + | void iot_received(String topic, String msg) | ||
| + | { | ||
| + | Serial.print(" | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | | ||
| + | |||
| + | myservo.write(msg.toInt()); | ||
| + | } | ||
| + | |||
| + | // Function started after the connection to the server is established | ||
| + | void iot_connected() | ||
| + | { | ||
| + | | ||
| + | | ||
| + | iot.subscribe(" | ||
| + | | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | |||
| + | // Print json config | ||
| + | iot.printConfig(); | ||
| + | // Initialize IoT library | ||
| + | iot.setup(); | ||
| + | |||
| + | myservo.attach(SERVO_PIN); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | // IoT behind the plan work, it should be periodically called | ||
| + | iot.handle(); | ||
| + | delay(200); | ||
| + | } | ||
| </ | </ | ||
| + | |||
| ==== Support ==== | ==== Support ==== | ||
| - | //Give some information on how to access help, how to get support in case of the trouble etc.// | + | info@ittgroup.ee |