Show Posts
Pages: 1 ... 49 50 [51] 52 53 ... 229
751  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.
752  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.
753  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.
754  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.
755  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;
}
756  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)
}
757  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 */);
758  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.
759  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);
760  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.
761  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");
}
762  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.
763  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?
764  Using Arduino / Project Guidance / Re: Robot arm problems with joysticks and base on: February 25, 2014, 06:25:47 pm
Quote
for (onex = 0; onex < 400; clawpos += 1);
  claw.write (clawpos);
  delay (20);
 
  for (onex = 0; onex > 500; clawpos -= 1);
  claw.write (clawpos);
  delay (20);

When does onex get incremented or decremented?
765  Development / Other Software Development / Re: New TFT Extension Library on: February 25, 2014, 05:55:36 pm
Update: I added a new function, TextButton, and for right now, it will display text in the center of the button (the outline of the button still needs to be drawn separately) and you can still use it as a normal button. I am still working on the library and if I can get the TextButton function to work properly, I will do the same to the rest of the buttons.

I also added a wall ball game.
Pages: 1 ... 49 50 [51] 52 53 ... 229