Show Posts
Pages: 1 ... 53 54 [55] 56 57 ... 232
811  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.
812  Using Arduino / Project Guidance / Re: Controls for a project on: February 24, 2014, 01:16:23 pm
How did you finally get it to work?
813  Using Arduino / Project Guidance / Re: College project; Smart home using wifi arduino on: February 24, 2014, 02:55:11 am
I find it really hard to believe that you didn't learn "Arduino" programming. Electrical/Electronic Engineering requires that you learn at least C programming. So if you don't recognize C programming or have absolutely no knowledge of C programming, then you are going to have a rough time doing this project. Your professor obviously taught you some C programming, otherwise why give a project if you never covered the material?

Another thing, you want to use an Android app to control everything, ok, but what app? Making your own app requires you to know Java. Do you know Java?

If you are completely new to Arduino, then the best thing you can do is buy a C/C++ programming book, and start from page one. You also have example sketches provided with the Arduino software, try them all and take notes.

At the moment, this project is completely out of your reach. But if you have the time and are willing to learn, you will eventually be able to do it.
814  Using Arduino / Project Guidance / Re: Controls for a project on: February 23, 2014, 09:25:29 pm
This might not help but it's worth a try.

I found out that my module does not like it when 5 volts is supplied, it too gives the same error. However I noticed that my module does not even need 3.3V to work. I could have the V+ wire off and it will still function correctly. If you can and dont break your current one, but if you can, make your own adapter the exact same way I made mine. Buy a PS2 extension cable and make your own. Or try different controllers. Mine is an INTEC and it took me a long while to figure out what my issue was, and it was only when I started to take apart the adapter (remove the V+ wire) did it finally work.
815  Using Arduino / Project Guidance / Re: Controls for a project on: February 23, 2014, 02:28:40 pm
Green wire is pin 13. Red = pin 10
816  Using Arduino / Project Guidance / Re: Arduino Mega2560 to Android via Bluetooth on: February 23, 2014, 01:39:49 pm
Reset button on what? What program are you using to talk to the arduino?
817  Using Arduino / Project Guidance / Re: Controls for a project on: February 22, 2014, 10:59:12 pm
What voltage are you supplying to it, 3.3 or 5? My wireless based only works at 3.3 so maybe yours does too.
818  Using Arduino / Project Guidance / Re: Controls for a project on: February 22, 2014, 08:36:20 pm
How is everything wired, can you provide pictures?
819  Using Arduino / Project Guidance / Re: Robot arm problems with joysticks and base on: February 22, 2014, 06:15:38 pm
3.3V and 5V produce different values when you read the pin. Make sure you calibrate it first, see what the maximum and minimum values are when you read the pin @ 3.3V.
820  Using Arduino / Project Guidance / Re: password activated garage on: February 22, 2014, 05:07:52 pm
It was a hint to use 5000 and not '5000'. The difference is one is a char and the other is an int/long.
Better yet, if you do a Serial.print of '5000', it equals 12336 and not the 5000 that you want.
821  Using Arduino / Programming Questions / Re: abort for-loop at any time on: February 22, 2014, 04:25:19 pm
Your not reading the signal pin in the for loop, your reading what it previously was and not what it currently is. Try to digitally read the pin while in the for loop.
822  Using Arduino / Project Guidance / Re: Controls for a project on: February 22, 2014, 04:21:01 pm
The library comes with an example sketch that shows you all the possibilities the library has to offer. Try it out.
823  Using Arduino / Programming Questions / Re: abort for-loop at any time on: February 22, 2014, 04:07:57 pm
break; will exit the for loop when it is called. So if you monitor the signal and it suddenly stops, you can call break; and it will exit the loop.

It does the same thing for while loops too.
824  Using Arduino / Project Guidance / Re: password activated garage on: February 22, 2014, 04:03:53 pm
Is it supposed to be '5000' or just 5000, because there is a major difference of the two.
825  Using Arduino / Project Guidance / Re: Controls for a project on: February 22, 2014, 01:50:29 pm
Here is a code to get you started, but you need to download the library in the Arduino Playground, link HERE.
Code:
#include <PS2X_lib.h>  //for v1.6

PS2X ps2x; // create PS2 Controller Class

int error = 0;
byte type = 0;
byte vibrate = 0;

int speed1 =128, speed2 = 128;

byte M1L = 5;// PWM
byte M1R = 3;// PWM
byte M2L = 6;// PWM
byte M2R = 9;// PWM

void setup(){
  Serial.begin(57600);

  //**************PAY ATTENTION*************
  pinMode(M1L, OUTPUT);                                // Establishes LEDPin as an output so the LED can be seen
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                                // Establishes LEDPin as an output so the LED can be seen
  pinMode(M2R, OUTPUT);
  error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

  if(error == 0)
    Serial.println("Controller found! You may now send commands");

  else if(error == 1)
    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");

  else if(error == 2)
    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");

  else if(error == 3)
    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");

  type = ps2x.readType();
  switch(type)
  {
  case 0:
    Serial.println("Unknown Controller type");
    break;
  case 1:
    Serial.println("DualShock Controller Found");
    break;
  }
}

void loop()
{
  if(error == 1) //skip loop if no controller found
    return;

  else { //DualShock Controller

    ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed

    if(ps2x.Button(PSB_L1))
    {
      // rotate turret left
    }
    else if(ps2x.Button(PSB_R1))
    {
      // rotate turret right
    }
    else
    {
      // do nothing
    }

    if(ps2x.Analog(PSS_LY) >= 136 && ps2x.Analog(PSS_LY) <= 255)//real center value is 128, but 140 is needed because controller is HIGHLY sensitive
    {
      speed1 = map(ps2x.Analog(PSS_LY),136 , 255, 0 , 255);
      analogWrite(M1L, speed1);
      digitalWrite(M1R, LOW);
    }
    else if(ps2x.Analog(PSS_LY) >= 0 && ps2x.Analog(PSS_LY) <= 120) //Same as above
    {
      speed1 = map(ps2x.Analog(PSS_LY),0 ,120 , 255 , 0);// create a set range for values and set output values respectively
      digitalWrite(M1L, LOW);
      analogWrite(M1R, speed1);
    } 
    else
    {
      digitalWrite(M1L, LOW);// all off
      digitalWrite(M1R, LOW);
    }
    //--------------------Right side motor----------------------- 
 
    if(ps2x.Analog(PSS_RY) >= 136 && ps2x.Analog(PSS_RY) <= 255)
    {
      speed2 = map(ps2x.Analog(PSS_RY),136 , 255, 0 , 255);
      analogWrite(M2L, speed2);
      digitalWrite(M2R, LOW);
    }

    else if(ps2x.Analog(PSS_RY) >= 0 && ps2x.Analog(PSS_RY) <= 120)
    {
      speed2 = map(ps2x.Analog(PSS_RY),0 ,120 , 255 , 0);
      digitalWrite(M2L, LOW);
      analogWrite(M2R, speed2);
    }

    else
   {
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);
    } 
  }

  delay(50); // not needed, but give the robot some time to finish inputted commands   
}

Pages: 1 ... 53 54 [55] 56 57 ... 232