Show Posts
Pages: 1 ... 17 18 [19] 20 21 ... 197
271  Using Arduino / Project Guidance / Re: Robot arm problems with joysticks and base on: February 26, 2014, 09:18:44 pm
You dont need a for loop to do that, just tell it where to go and unless the value changes, the servo will stay the same.
272  Using Arduino / Project Guidance / Re: Robot arm problems with joysticks and base on: February 26, 2014, 07:41:21 pm
It should be
Quote
for (clawpos = 0; clawpos < 450; clawpos += 1);
for (clawpos = 0; clawpos > 750; clawpos -= 1);
Because you never increment or decrement onex in the for loops.

But upon closer inspection, onex is a reading from the analog input A0, so why are you using FOR loops at all and not mapping the value?

clawpos = map( onex, 0, 1023, 0, 180);
273  Using Arduino / Programming Questions / Re: While loop exit condition on: February 26, 2014, 04:23:58 am
Check your brackets, your not reading the button in the while loop.
274  Using Arduino / Programming Questions / Re: While loop exit condition on: February 26, 2014, 03:58:39 am
You need to read the button again, this time in the while loop.
275  Using Arduino / Programming Questions / Re: Need help with PWM Motor on: February 26, 2014, 01:38:48 am
Actually, if the motor is to be on forever when the button is pressed, then all you need is.

if(digitalRead(2) )  analogWrite(motor pin, 200); //no brackets needed for one line of code.
The motor will now always be on until commanded otherwise.
276  Using Arduino / Programming Questions / Re: Need help with PWM Motor on: February 26, 2014, 01:33:36 am
You need to add boolean latch = false; at the top with the rest of your pins. Another thing, if the motor is to stay on forever when the button is pressed, then why have an else statement that makes it turn off?

To answer your problem, you need another if statement that looks to see if latch is true, then if it is, motor goes on.
277  Using Arduino / Programming Questions / Re: Need help with PWM Motor on: February 26, 2014, 01:16:54 am
If button 2 is pressed and nothing else changes "latch", then yes, latch will always be true.
Quote
if(digitalRead(2) == HIGH)
{
  latch = true;
}
278  Using Arduino / Programming Questions / Re: Need help with PWM Motor on: February 26, 2014, 01:01:27 am
Yes, but will you be using that same button to then turn it off too?

To use the same button to turn it on/off, you need a latch. 

Example pseudo code:
Code:
boolean latch = LOW; // declaired at top of code

// inside the loop() or a function
if(digitalRead(2) == HIGH)
// you will need another variable to block this IF statement if the button is held down ie. Prev_state.
// Also debouncing may be needed, but you have an example code under Examples with the Arduino software
{
  latch = ! latch;
}

To do it with two different buttons.
Code:
if(digitalRead(2) == HIGH)
{
  latch = true; // digital/analogWrite( motor pin, set speed)
}
else if(digitalRead(3) == HIGH)
{
  latch = false; // digital/analogWrite( motor pin, 0 or LOW)
}
279  Using Arduino / Programming Questions / Re: Need help with PWM Motor on: February 26, 2014, 12:18:10 am
Ok, then get rid of all the unneeded things like
Quote
int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
and just have analogWrite(motorPin, /* Pick a number between 0 - 255 */);
280  Using Arduino / Programming Questions / Re: Coding an XOR on: February 26, 2014, 12:04:02 am
Why not just do this if(digitalRead(2) ^ digitalRead(3)), it works. Granted this only works for bits, you will need a micro to XOR other/different data types.
281  Using Arduino / Project Guidance / Re: Robot arm problems with joysticks and base on: February 25, 2014, 09:59:47 pm
You still didn't fix the issue and you added an unneeded semicolon.

Quote
for (onex = 0; onex < 450; clawpos += 1);
for (onex = 0; onex > 750; clawpos -= 1);
282  Using Arduino / Programming Questions / Re: Bluetooth Controlled Robot Science Fair Project Help Requested on: February 25, 2014, 09:50:02 pm
He has the same post in Programming Questions.
283  Using Arduino / Programming Questions / Re: Help with Science Fair Project Code. on: February 25, 2014, 09:48:18 pm
MOVED:

You are doing the same thing I did for my college seminar project. Mine was made with Legos, my own motor driver, a UNO Rev3 and a Samsung Galaxy tablet.

This is an older version, but it relys on single characters to control the robot. I also have the better version, but we will get to that later.
Code:
/*
simple control test
*/

volatile int gear = 150; //default speed First Gear

volatile char val;         // variable to receive data from the serial port

byte M1L = 3;              // PWM left drive motor
byte M2L = 5;              // PWM left drive motor
byte M1R = 9;              // PWM right drive motor
byte M2R = 6;              // PWM right drive motor
byte ledpin = 13;          // LED connected to pin 2 (on-board LED)

/*IMPORTANT*/
//M1 => High & M2 => Low: forward movement
//M1 => Low & M2 => High: Backward movement

void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(M1L, OUTPUT);                               
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                               
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 115200bps
 
  Serial.println("Commands, Press * to bring up help menu");
}

void loop() {
  if( Serial.available() )       // if data is available to read
  {
    digitalWrite(ledpin, HIGH);
    val = Serial.read();
    volatile int skewGear = gear/2;
    if(val == '1')
    {
      Serial.println("First Gear ");
      gear = 150;
    }
    else if (val == '2')
    {
      Serial.println("Second Gear ");
      gear = 200;
    }
    else if (val == '3')
    {
      Serial.println("Third Gear ");
      gear = 255;
    }


    if( val == 'W' || val == 'w' )//forwards               
    {
      Serial.println("Moving Forwards");
      //      Left Motor     :     Right Motor
      analogWrite(M1L, gear);
      analogWrite(M1R, gear);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'S' || val == 's' )//backwards             
    {
      Serial.println("Moving Backwards");
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      analogWrite(M2L, gear);
      analogWrite(M2R, gear);                   
    }
    else if( val == 'A' || val == 'a' )//Left         
    {
      Serial.println("LEFT");
      digitalWrite(M1L, LOW);
      analogWrite(M1R, gear);
      analogWrite(M2L, gear);
      digitalWrite(M2R, LOW);                     
    }
    else if( val == 'D' || val == 'd' )             
    {
      Serial.println("RIGHT");   
      analogWrite(M1L, gear);
      digitalWrite(M1R, LOW);
      digitalWrite(M2L, LOW);
      analogWrite(M2R, gear);                 
    }
    else if( val == 'T' || val == 't' )             
    {
      Serial.println("Skew Left Forward");   
      analogWrite(M1L, skewGear);
      analogWrite(M1R, gear);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'Y' || val == 'y' )             
    {
      Serial.println("Skew Right Forward"); 
      analogWrite(M1L, gear);
      analogWrite(M1R, skewGear);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'G' || val == 'g' )             
    {
      Serial.println("Skew Left Backward");   
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      analogWrite(M2L, skewGear);
      analogWrite(M2R, gear);                 
    }
    else if( val == 'H' || val == 'h' )             
    {
      Serial.println("Skew Right Backward");   
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      analogWrite(M2L, gear);
      analogWrite(M2R, skewGear);                 
    }
    else if(val == ' ' || val == 'x' || val == 'X'){ 
      digitalWrite(M1L, LOW);
      digitalWrite(M1R, LOW);
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);
    }
    else if(val == '*'){
      Help();
    }   
  }
  else{
    digitalWrite(ledpin, LOW);
  }
}

void Help() {
  Serial.println("W = Forward");
  Serial.println("S = Backward");
  Serial.println("A = Left");
  Serial.println("D = Right");
  Serial.println("T = Skew Forward Left");
  Serial.println("Y = Skew Forward Right");
  Serial.println("G = Skew Backward Left");
  Serial.println("H = Skew Backward Right");
  Serial.println("Space Bar = All stop");
}
284  Using Arduino / Programming Questions / Re: having problems with addressable led sample code on: February 25, 2014, 08:27:40 pm
Make sure it is not double foldered.
285  Using Arduino / Programming Questions / Re: having problems with addressable led sample code on: February 25, 2014, 08:01:04 pm
Quote
Blink.ino:2:21: error: FastLED.h: No such file or directory
The compiler is unable to find your library, where did you put it?
Pages: 1 ... 17 18 [19] 20 21 ... 197