This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
digispark:tutorials:robot [2016/02/19 19:59] digistump |
digispark:tutorials:robot [2016/06/09 12:03] (current) |
||
|---|---|---|---|
| Line 56: | Line 56: | ||
| Solder the female (non-stackable) headers to your Digispark Pro. | Solder the female (non-stackable) headers to your Digispark Pro. | ||
| - | Assemble the Wings Kits - using the male headers from the BLE, BT, WiFi Kit or extra ones - per the instructions here: http://digistump.com/wiki/digispark/tutorials/wings | + | Assemble the Wings Kits - using the male headers from the BLE, BT, WiFi Kit or extra ones - per the instructions here: http://digistump.com/wiki/digispark/tutorials/wings **NOTE** On the Oak the 5V pin is actually for 3.3V |
| Assemble the BT, BLE, or WiFi kit (using the correct tutorial for that kit) if applicable - using the included 9 pin stackable headers and the extra 3 pin female header. See the following photos for an example of how it should look with those headers (this is a BT shield, but the BLE and WiFi header setup would be the same): | Assemble the BT, BLE, or WiFi kit (using the correct tutorial for that kit) if applicable - using the included 9 pin stackable headers and the extra 3 pin female header. See the following photos for an example of how it should look with those headers (this is a BT shield, but the BLE and WiFi header setup would be the same): | ||
| Line 142: | Line 142: | ||
| =====Programming:===== | =====Programming:===== | ||
| + | |||
| + | **NOTE**: The example included with the Oak is incorrect - please use the Oak example below. | ||
| + | |||
| Copy and upload the following sketch. This sketch will cause the bot to cycle through each of its movement abilities at full speed, 5 seconds each. | Copy and upload the following sketch. This sketch will cause the bot to cycle through each of its movement abilities at full speed, 5 seconds each. | ||
| - | BT, BLE, and WiFi Examples coming shortly with a new IDE release. | + | BT, BLE, and WiFi Examples included with the IDE. |
| + | **For the Digispark/Digispark Pro:** | ||
| <code arduino> | <code arduino> | ||
| void setup() { | void setup() { | ||
| Line 210: | Line 214: | ||
| digitalWrite(5, LOW); | digitalWrite(5, LOW); | ||
| analogWrite(0, 255 - botSpeed); | analogWrite(0, 255 - botSpeed); | ||
| + | analogWrite(1, botSpeed); | ||
| + | } | ||
| + | |||
| + | void botStop(){ | ||
| + | digitalWrite(2,LOW); | ||
| + | digitalWrite(5,LOW); | ||
| + | analogWrite(0,0); | ||
| + | analogWrite(1,0); | ||
| + | } | ||
| + | |||
| + | void botInit(){ | ||
| + | pinMode(0,OUTPUT); | ||
| + | pinMode(1,OUTPUT); | ||
| + | pinMode(2,OUTPUT); | ||
| + | pinMode(5,OUTPUT); | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | **For the Oak:** | ||
| + | <code arduino> | ||
| + | void setup() { | ||
| + | // put your setup code here, to run once: | ||
| + | botInit(); | ||
| + | } | ||
| + | |||
| + | |||
| + | void loop() { | ||
| + | // put your main code here, to run repeatedly: | ||
| + | botForward(1023); //speed can be any value from 0 (stopped) to 1023 (full) | ||
| + | delay(5000); | ||
| + | botReverse(1023); | ||
| + | delay(5000); | ||
| + | botRight(1023); | ||
| + | delay(5000); | ||
| + | botHardRight(1023); | ||
| + | delay(5000); | ||
| + | botLeft(1023); | ||
| + | delay(5000); | ||
| + | botHardLeft(1023); | ||
| + | delay(5000); | ||
| + | botStop(); | ||
| + | delay(5000); | ||
| + | } | ||
| + | |||
| + | void botForward(int botSpeed){ | ||
| + | digitalWrite(2, HIGH); | ||
| + | digitalWrite(5, HIGH); | ||
| + | analogWrite(0, 1023 - botSpeed); | ||
| + | analogWrite(1, 1023 - botSpeed); | ||
| + | } | ||
| + | |||
| + | void botReverse(int botSpeed){ | ||
| + | digitalWrite(2, LOW); | ||
| + | digitalWrite(5, LOW); | ||
| + | analogWrite(0, botSpeed); | ||
| + | analogWrite(1, botSpeed); | ||
| + | } | ||
| + | |||
| + | void botRight(int botSpeed){ | ||
| + | digitalWrite(2, LOW); | ||
| + | digitalWrite(5, HIGH); | ||
| + | analogWrite(0, 0); | ||
| + | analogWrite(1, 1023 - botSpeed); | ||
| + | } | ||
| + | |||
| + | void botHardRight(int botSpeed){ | ||
| + | digitalWrite(2, LOW); | ||
| + | digitalWrite(5, HIGH); | ||
| + | analogWrite(0, botSpeed); | ||
| + | analogWrite(1, 1023 - botSpeed); | ||
| + | } | ||
| + | |||
| + | void botLeft(int botSpeed){ | ||
| + | digitalWrite(2, HIGH); | ||
| + | digitalWrite(5, LOW); | ||
| + | analogWrite(0, 1023 - botSpeed); | ||
| + | analogWrite(1, 0); | ||
| + | } | ||
| + | |||
| + | void botHardLeft(int botSpeed){ | ||
| + | digitalWrite(2, HIGH); | ||
| + | digitalWrite(5, LOW); | ||
| + | analogWrite(0, 1023 - botSpeed); | ||
| analogWrite(1, botSpeed); | analogWrite(1, botSpeed); | ||
| } | } | ||