Pages: 1 2 [3]   Go Down
Author Topic: need some beginners direction in making a rc blimp  (Read 2757 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still no luck after looking at this thread (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247084671/all). any suggestions?

Code:
#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");
}
« Last Edit: November 23, 2010, 01:43:15 pm by caiol611 » Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 23, 2010, 03:42:25 am by John_Smith » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow that small, if my wife saw that on the bench she would swat it with a newspaper to "debug" it  smiley-wink
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Pages: 1 2 [3]   Go Up
Jump to: