Show Posts
Pages: 1 ... 49 50 [51] 52 53 ... 228
751  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.
752  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);
753  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.
754  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");
}
755  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.
756  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?
757  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?
758  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.
759  Using Arduino / Programming Questions / Re: The difference is returning a value which is very large on: February 25, 2014, 03:22:20 pm
There is a function that will convert your values to a char array (string), this useful function is sprintf(). Look it up and see how it works, then adapt it in your code.
760  Using Arduino / Project Guidance / Re: Need help with button combinations on: February 25, 2014, 03:18:53 pm
The code is doing something, the question is what? The code is using the serial monitor, which is set at a certain baud rate, to display a certain variable. You need to set up your Leds to react to that variable, but first you need to see that variable.

Your serial monitor might not be set to the baud rate in the code, but you can change it to do so, either the monitor itself or the code.
761  Using Arduino / Project Guidance / Re: Need help with button combinations on: February 25, 2014, 01:43:44 pm
I told you it is very easy. Wire the Leds and the rest of your buttons
Code:
#define Num_of_Buttons 3

boolean buttons[Num_of_Buttons] = {2,3,4};

byte LED_byte = 0;
void setup()
{
Serial.begin(115200);
for(byte i = 0; i < Num_of_Buttons; i++)
  pinMode(2+i, INPUT);
}

void loop() {
  for(byte i = 0; i < Num_of_Buttons; i++) // cycle through button array.
  {
    bitWrite(LED_byte, i, digitalRead(2+i)); // 2 = first button, 2 + i = cycle through all the buttons.
  }
  Serial.println(LED_byte);
}
762  Using Arduino / Programming Questions / Re: Random command appearing on: February 25, 2014, 02:18:22 am
Hello again.

Ok what happens if you hold the left Dpad button and release, do you still get the same message? By any chance the right Dpad button feel looser then the rest? It is possibly the right Dpad touch pad (the rubber part inside) is stuck, in which case you would need to open up the controller to find out.
763  Using Arduino / Programming Questions / Re: Using Serial to implement a password using other than numbers on: February 24, 2014, 10:35:13 pm
The strings are only equal when the result is 0, not 1 or true.
764  Using Arduino / Project Guidance / Re: Help with 6 button, 6 led code on: February 24, 2014, 04:36:14 pm
Assign a button a binary value and use the bitWrite function to turn on the led.
765  Using Arduino / Project Guidance / Re: Help with 6 button, 6 led code on: February 24, 2014, 01:26:31 pm
You are over thinking your code. It is as simple as using arrays.

USE CODE TAGS, like so. See nice and neat.
Code:
byte Buttons[6]= { 2,3,4,5,6,7 }; // at top of code "Global array"
byte LEDs[6]  = {8,9,10,11,12,13}; // at top of code "Global array"

//Inside setup(), this is all you need unless you want to use the serial monitor too
for(byte i = 2; i <= 7; i++)
{
  pinMode(Buttons[ i ], INPUT); // i = 2
  pinMode(LEDs[ i + 6 ], OUTPUT); i  + 6 = 8, and so on to i + 6 = 13.
}

// In the loop(), use another FOR loop to cycle through the arrays to read the buttons and output the corresponding LED.

One more thing, the digital pins, unless they have the ~ next to them, ONLY output a 1 or 0.
If you want to control the brightness of the LED, then you need to use analogWrite and one of pin with the ~ next to it.
Pages: 1 ... 49 50 [51] 52 53 ... 228