Go Down

Topic: need some beginners direction in making a rc blimp (Read 3 times) previous topic - next topic

caiol611

#30
Nov 23, 2010, 07:20 am Last Edit: Nov 23, 2010, 07:43 pm by caiol611 Reason: 1
still no luck after looking at this thread (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247084671/all). any suggestions?

Code: [Select]

#include <Servo.h>

boolean inputReadyCh1;
boolean inputReadyCh3;

const int MIN_CH1 = 970;
const int MAX_CH1 = 1800;
const int MIN_CH3 = 1080;  //minimum PPM value read for throttle stick
const int MAX_CH3 = 1800;  //maximum PPM value read for throttle stick
const int PIN_CH1 = 2;  //input pin for steering left/right
const int PIN_CH2 = 4;  //input pin for steering up/down
const int PIN_CH3 = 3;  //input pin for throttle
const int PIN_LEFTMOTOR = 5;  //output pin for left motor
const int PIN_RIGHTMOTOR = 6;  //output pin for right motor
const int PIN_SERVO = 9;  //output pin for servo steering up/down

int valueCh1;
int valueCh3;

Servo servoCh2;

unsigned long pulseLengthCh1;
unsigned long pulseLengthCh2;
unsigned long pulseLengthCh3;
unsigned long startTimeCh1;
unsigned long startTimeCh3;

void setup() {
 servoCh2.attach(PIN_SERVO);
 pinMode(PIN_CH1, INPUT);
 pinMode(PIN_CH3, INPUT);
 pinMode(PIN_LEFTMOTOR, OUTPUT);
 pinMode(PIN_RIGHTMOTOR, OUTPUT);
 
 attachInterrupt(0, ISR_Ch1, CHANGE);
 attachInterrupt(1, ISR_Ch3, CHANGE);
 //Serial.begin(9600);
}

void ISR_Ch1() {
 if(digitalRead(PIN_CH1) == HIGH) {
   startTimeCh1 = micros();
 } else {
   pulseLengthCh1 = micros() - startTimeCh1;
   inputReadyCh1 = true;
 }
}

void ISR_Ch3() {
 if(digitalRead(PIN_CH3) == HIGH) {
   startTimeCh3 = micros();
 } else {
   pulseLengthCh3 = micros() - startTimeCh3;
   inputReadyCh3 = true;
 }
}

void loop() {
 if(inputReadyCh1) {
   inputReadyCh1 = false;
   valueCh1 = constrain(pulseLengthCh1, MIN_CH1, MAX_CH1);
   
   int centralValue = (MIN_CH1 + MAX_CH1) / 2;
   
   if(valueCh1 < centralValue + 100) {  //100 is just a spacer value so the stick has
     digitalWrite(PIN_LEFTMOTOR, LOW);  //a bit of play when it is neutral
   } else if(valueCh1 > centralValue + 100) {
     digitalWrite(PIN_RIGHTMOTOR, LOW);
   }
 }
 
 if(inputReadyCh3) {
   inputReadyCh3 = false;
   
   if(pulseLengthCh3 < MIN_CH3) {
     pulseLengthCh3 = MIN_CH3;
   } else if(pulseLengthCh3 > MAX_CH3) {
     pulseLengthCh3 = MAX_CH3;
   }
   
   valueCh3 = map(pulseLengthCh3, MIN_CH3, MAX_CH3, 0, 255);
   analogWrite(PIN_LEFTMOTOR, valueCh3);
   analogWrite(PIN_RIGHTMOTOR, valueCh3);
 }
 
 pulseLengthCh2 = pulseIn(PIN_CH2, HIGH);
 servoCh2.writeMicroseconds(pulseLengthCh2);
 
 //Serial.println("Ch3 value: " + String(valueCh3));
 //Serial.println("Time for pulseIn 2: " + String(time2));
 //Serial.println("Time for pulseIn 3: " + String(time3));
 
 //Serial.println("Ch1: " + String(pulseLengthCh1));  //for debugging
 //Serial.println("Ch2: " + String(pulseLengthCh2));
 //Serial.println("Ch3: " + String(pulseLengthCh3) + "\n");
}


Boffin1

#31
Nov 23, 2010, 09:41 am Last Edit: Nov 23, 2010, 09:42 am by John_Smith Reason: 1
To reduce the weight while still "using" the arduino Dm you can remove the chip after programming and put it in a socket with a crystal and a couple of caps.
With my mobile phone I can call people and talk to them -  how smart can you get ?

zoomkat

The below page recently posted to the forum shows making the arduino very small.

http://www.geocities.jp/arduino_diecimila/obaka/project-2/index_en.html
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Boffin1

Wow that small, if my wife saw that on the bench she would swat it with a newspaper to "debug" it  ;)
With my mobile phone I can call people and talk to them -  how smart can you get ?

Go Up