SHOW:
|
|
- or go back to the newest paste.
1 | // Led 4 | |
2 | const int ledPin = 3; | |
3 | ||
4 | // Use Arduino-Tiny | |
5 | #include "pins_arduino.h" | |
6 | ||
7 | //Servo | |
8 | #define USE_TIMER1 | |
9 | #include "Servo8Bit.h" | |
10 | Servo8Bit Servo1; | |
11 | int attachpin1 = 2; // PB2 | |
12 | int servopos = 0; | |
13 | ||
14 | // Serial | |
15 | #include <NewSoftSerial.h> | |
16 | NewSoftSerial mySerial(0, 1); // PB0, PB1 | |
17 | ||
18 | int inChar; | |
19 | char inBuff[20]; | |
20 | int inBuff_i = 0; | |
21 | ||
22 | // Loop | |
23 | int lwait = 0; | |
24 | int lrun = 0; | |
25 | uint32_t timer; | |
26 | ||
27 | ||
28 | void setup() | |
29 | { | |
30 | mySerial.begin(9600); | |
31 | mySerial.println("... "); | |
32 | ||
33 | - | pinMode(buttonPin, INPUT); |
33 | + | |
34 | ||
35 | inBuff[1] = '\0'; | |
36 | inBuff_i = -1; | |
37 | lwait = 1; | |
38 | } | |
39 | ||
40 | ||
41 | void loop() | |
42 | { | |
43 | if (lwait == 1) { | |
44 | digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(200); | |
45 | digitalWrite(ledPin, HIGH); delay(200); digitalWrite(ledPin, LOW); delay(200); | |
46 | ||
47 | mySerial.print("Going to: "); mySerial.println(servopos); | |
48 | ||
49 | //mySerial.end(); | |
50 | - | mySerial.end(); |
50 | + | //delay(1000); |
51 | - | delay(1000); |
51 | + | |
52 | Servo1.attach(attachpin1); | |
53 | - | // Servo1.attach(attachpin1); // activate this return compile error |
53 | + | //Servo1.write(servopos); // activate this return compile error |
54 | - | // Servo1.write(servopos); |
54 | + | //delay(1000); |
55 | - | // delay(1000); |
55 | + | //Servo1.detach(); |
56 | - | // Servo1.detach(); |
56 | + | |
57 | //mySerial.begin(9600); | |
58 | - | mySerial.begin(9600); |
58 | + | |
59 | lwait = 0; | |
60 | } | |
61 | ||
62 | while (mySerial.available() > 0) { | |
63 | inChar = mySerial.read(); | |
64 | inBuff_i ++; | |
65 | ||
66 | if (isDigit(inChar)) { | |
67 | inBuff[inBuff_i]= inChar; | |
68 | } | |
69 | ||
70 | if (inChar == '\n') { // readln first digits chars as servopos | |
71 | inBuff[inBuff_i]= '\0'; | |
72 | ||
73 | // servopos = atoi(inBuff); | |
74 | - | servopos = atoi(inBuff); |
74 | + | servopos ++; // or advance servo with each \n |
75 | - | // servopos ++; // or advance servo with each \n |
75 | + | |
76 | inBuff[1] = '\0'; | |
77 | inBuff_i = -1; | |
78 | lwait = 1; | |
79 | } | |
80 | } | |
81 | ||
82 | } |