Show Posts
Pages: 1 [2] 3 4 ... 251
16  Using Arduino / Programming Questions / Re: if else statements with analogWrite functions very slow sonar feedback response on: September 14, 2014, 12:16:25 am
What kind of ping sensor do you have the 3 pin or 4 pin sensor? You can and probably should use the NewPing library, it is better and more efficient than using pulseIn or using delayMicroseconds().
17  Using Arduino / Programming Questions / Re: 4x4 keypad for menu driven functions on: September 14, 2014, 12:12:43 am
When you are inside the switch case, you will need to re-read the chars again and collect four, so you would probably want a while loop that will allow you to stay inside the case and continue to collect the numbers.

So what you want to write is this:
1) read the keypad and get a letter, this letter will bring you into the corresponding case.
2) using a while or do while loop, you re-read the keypad and collect the correct amount of numbers, anymore and you can show an error message
3) after all the numbers have been obtained, you add the null character.
4) use atoi and do whatever you want with the value
18  Using Arduino / Programming Questions / Re: 4x4 keypad for menu driven functions on: September 13, 2014, 11:55:44 pm
If you use atoi(), the array will need to be Null terminated. Meaning the 4th index will need to be set to a null character (myArray[4] = '\0')

Here is an example.
Code:
myArray[0] = '1';
myArray[1] = '5';
myArray[2] = '9';
myArray[3] = '3';
myArray[4] = '\0';

int Value = atoi(myArray);
19  Using Arduino / Programming Questions / Re: if else statements with analogWrite functions very slow sonar feedback response on: September 13, 2014, 11:51:00 pm
The culprits are all those delays in your code. The delay() function blocks the code from doing anything else until the delay is finished. So all the delay(150)and delay(500) add up, even the delayMicroseconds() too. The best thing to do is get rid of all the delays and look into the example sketch Blink Without Delay. Another solution is what another user Robin2 has made (if I can find the thread I will make a link to it)

Found the link, Demonstration code for several things at the same time
20  Using Arduino / Programming Questions / Re: 4x4 keypad for menu driven functions on: September 13, 2014, 11:37:20 pm
Make Num an array, NOT String Object and use a counter to see how many digits are entered. If the user enters more than 4, clear the array and start over.

It's very simple.
21  Using Arduino / Programming Questions / Re: How to read the position of 6 switches. on: September 13, 2014, 10:22:55 pm
You can use this sample sketch to check the overall result of the switches.

Code:
byte output;

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

void loop()
{
  output = 0x01; // set output to 1
 
  for(byte i = 2; i <= 7; i++)
    output &= digitalRead(i); // reads pins 2 - 7, and using the AND logic, it multiples
                              //each result by output(0x01) and if any of the switchs are LOW
                              // output will equal 0

    if(output == 0x01) // if all switches were high, then output is still 0x01
    {
      // solenoid on
    }
    else // output = 0x00, a switch was LOW
    {
     //off
    }
}

NOTE: Make sure you have pull down resistors connected to the arduino pins, otherwise you may have incorrect results.
22  Using Arduino / Motors, Mechanics, and Power / Re: DC motor on: September 13, 2014, 07:52:39 pm
No, when you use the serial monitor, you need to send it yourself, it doesn't do it automatically. Try PuTTY, I use it myself and it does exactly what you want.
23  Using Arduino / Project Guidance / Re: Could I connect multiple 8x8 LED matricies (w/ MAX2719)? on: September 13, 2014, 07:43:39 pm
Easy, each one has 5 pins at the top and bottom.

(Top) VCC, GND, DOUT, CLK and CS.
(Bottom) VCC, GND, DIN, CLK and CS

All the CLK must be connected, as well as all the CS, top or bottom, it doesn't matter. What does matter is the DIN and DOUT pins, the first DIN will come from the Arduino, and then all the rest get DOUT(first display) -> DIN(second display), then DOUT(second display) -> DIN(third display) ... and so on.

These do take a bit of power each, so having multiple connected will take even more so, what you should do is power them with a good 5V wall charger at +700mA .

To get them to work you can either write the code yourself using shiftOut() or one of the already made libraries. (Search arduino 8x8 Dot matrix library)

I use LEDControl found HERE
24  Using Arduino / Project Guidance / Re: Working with RF Module on: September 13, 2014, 06:54:04 pm
Those don't use the virtual wire library, they are actually very straight forward. If you set D0 on the transmitter side to HIGH, then D0 on the receiver side will be HIGH.

What are you trying to do with them exactly, what is being controlled?
25  Using Arduino / Programming Questions / Re: Expected Unqualified-Id Before ')' Token on: September 12, 2014, 06:22:49 pm
You need to call your functions with () on the end of them, not just local; or auto;
26  Using Arduino / Programming Questions / Re: Programming Help. Dice game. on: September 12, 2014, 04:23:02 pm
Try this.

Code:
int LEDRED = 11;
int LEDGREEN = 9;
int counter = 0;

void setup ()
{
  Serial.begin(9600);
  randomSeed(analogRead(0)); //Seed the random number generator
  pinMode(LEDGREEN, OUTPUT); // Configure green LED
  pinMode(LEDRED,OUTPUT); // Configure red LED
  digitalWrite(9, LOW); // Making sure the green LED is off
  digitalWrite(11, LOW); // Making sure the red LED is off
  Serial.println("Welcome to the dice game!");
}

void loop()
{
  int answer;
  int user;
  int computer;

  Serial.print('\n');
  Serial.print("Want to play? (1 = yes, 2 = no)");
  while(Serial.available() <=0); //Waiting while the user inputs vaule

  digitalWrite(9, LOW); // Making sure the green LED is off
  digitalWrite(11, LOW); // Making sure the red LED is off

  answer = Serial.parseInt(); //Recieves the vaule from the user
  switch(answer)
  {
  case 1:
    if(counter < 3) // regular
    {
      user = random(1,7);
      computer = random(1,7);
    }
    else
    {
      user = random(4,7);
      computer = random(1,3);
    }

    Serial.print('\n');
    Serial.println("The user rolls a");
    Serial.println(user);
    Serial.println("The computer rolls a");
    Serial.println(computer);

    if(user > computer)
    {
      counter = 0;
      Serial.println("You win!!!!");
      digitalWrite(LEDGREEN, HIGH);
      delay(3000);
    }

    else if(user < computer)
    {
      counter ++;
      Serial.println("You loose, Computer wins!");
      digitalWrite(LEDRED, HIGH);
      delay(3000);
    }
    else /*if(user ==computer)*/ // not needed anymore
    {
      counter =0;
      Serial.println("It's a tie!");
      digitalWrite(LEDRED, HIGH);
      digitalWrite(LEDGREEN, HIGH);
      delay(3000);
    }
    break;

  case 2:
    Serial.print('\n');
    Serial.print("You've hurt my feelings, I really wanted to play :/");
    break;

  default:
    Serial.println("Invalid response, please enter a 1 or 2");
  }
}
27  Using Arduino / Programming Questions / Re: Strange conflict between SdFat.write() and Serial.print() on: September 12, 2014, 04:10:25 pm
I'm not sure if this will make a difference, but you can try to put your strings in the flash memory with F().

Example:
Code:
Serial.print(F("got array [")); Serial.print(sample_arr); Serial.println(F("]"));
28  Using Arduino / Programming Questions / Re: Programming Help. Dice game. on: September 12, 2014, 04:01:40 pm
Post your code, and please use code tags, its the # symbol above the smiley face.
29  Using Arduino / Programming Questions / Re: Programming Help. Dice game. on: September 12, 2014, 03:53:29 pm
Quote
reseting to zero every time the game loops?
It should only reset when the user wins.
30  Using Arduino / Programming Questions / Re: Programming Help. Dice game. on: September 12, 2014, 03:09:15 pm
Now when I place that in my code where would I place it? I would want it before the void loop, so I am thinking in the void setup?

It's practically already in your code, you just need to figure out where that is. (Hint: When the computer wins, counter++, when the user wins counter = 0.)

All you need to do after is have an if statement that sees if the user has lost 3 times and then on the next game, the user wins.

Quote
so I am thinking in the void setup?
A whole lot of good that will do for you. smiley-wink
Pages: 1 [2] 3 4 ... 251