你硬碟有 SoftwareServo.h file嗎?
應該是少這行:
int val;
....
....
val = map(val, 0, 2200, 0, 179);
=========================
An Example
The following code lets you control Servo on pin2 by potentiometer on analog 0
#include <SoftwareServo.h>
SoftwareServo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(2); // attaches the servo on pin 2 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
SoftwareServo::refresh();
}作者: vegewell 時間: 2011-4-17 12:08 本帖最後由 vegewell 於 2011-4-17 12:09 編輯
我只能提供類似的code做參考 畢竟範本RF不是 TG-11,
code
;
// Maurice Ribble
// 8-30-2009
// http://www.glacialwanderer.com/hobbyrobotics
// Used Arduino 0017
// This is a simple test app for some cheap RF transmitter and receiver hardware.
// RF Transmitter: http://www.sparkfun.com/commerce/product_info.php?products_id=8945
// RF Receiver: http://www.sparkfun.com/commerce/product_info.php?products_id=8948
// This says whether you are building the transmistor or reciever.
// Only one of these should be defined.
//#define TRANSMITTER
#define RECEIVER
// Arduino digital pins
#define BUTTON_PIN 2
#define LED_PIN 13
// Button hardware is setup so the button goes LOW when pressed
#define BUTTON_PRESSED LOW
#define BUTTON_NOT_PRESSED HIGH
void setup()
{
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(1200); // Hardware supports up to 2400, but 1200 gives longer range
}
#ifdef TRANSMITTER
void loop()
{
static int prev_button = BUTTON_NOT_PRESSED; // Previous button press value
int cur_button; // Current button press value
cur_button = digitalRead(BUTTON_PIN);
if ((prev_button == BUTTON_NOT_PRESSED) && (cur_button == BUTTON_PRESSED))
{
writeUInt(271); // Put any number you want to send here (71 is just a test)
}
delay(50); // Debounce button
prev_button = cur_button;
}
#endif //TRANSMITTER
#ifdef RECEIVER
void loop()
{
boolean light_led = false;
if (readUInt(true) == 271) // Check to see if we got the 71 test number
{
light_led = true;
}