daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Jun 29th, 2012 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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);  
  34.    pinMode(ledPin, OUTPUT);    
  35.  
  36.    inBuff[1] = '\0';
  37.    inBuff_i = -1;
  38.    lwait = 1;
  39. }
  40.  
  41.  
  42. void loop()
  43. {
  44.   if (lwait == 1) {
  45.       digitalWrite(ledPin, HIGH);  delay(200); digitalWrite(ledPin, LOW);  delay(200);
  46.       digitalWrite(ledPin, HIGH);  delay(200); digitalWrite(ledPin, LOW);  delay(200);
  47.  
  48.       mySerial.print("Going to: "); mySerial.println(servopos);
  49.      
  50.       mySerial.end();
  51.       delay(1000);
  52.    
  53.       // Servo1.attach(attachpin1);  // activate this return compile error
  54.       // Servo1.write(servopos);
  55.       // delay(1000);
  56.       // Servo1.detach();
  57.      
  58.       mySerial.begin(9600);
  59.       mySerial.println("End Running! ");
  60.       lwait = 0;
  61.   }
  62.  
  63.   while (mySerial.available() > 0) {
  64.     inChar = mySerial.read();
  65.     inBuff_i ++;
  66.    
  67.     if (isDigit(inChar)) {                        
  68.         inBuff[inBuff_i]= inChar;
  69.     }
  70.    
  71.     if (inChar == '\n') {           // readln first digits chars as servopos
  72.       inBuff[inBuff_i]= '\0';
  73.  
  74.       servopos = atoi(inBuff);
  75.       // servopos ++;   // or advance servo with each \n
  76.  
  77.       inBuff[1] = '\0';
  78.       inBuff_i = -1;
  79.       lwait = 1;
  80.     }
  81.   }
  82.  
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top