Show Posts
Pages: 1 ... 60 61 [62] 63 64 ... 227
916  Using Arduino / Programming Questions / Re: Shifting contents of an array on: January 27, 2014, 06:54:36 pm
Your code should look like this, simple and sweet.

Using Graynomad's code.
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define N_CHARS  ((sizeof(Compass)/sizeof(Compass[0]))-1)

LiquidCrystal_I2C lcd(0x20,20,4);  // set the LCD address to 0x20 for a 16 chars and 2 line display

char Compass[21] = {"N....E....S....W...."};
int potVal;
void setup()
{
  lcd.init();                      // initialize the lcd 
  lcd.backlight();
}

void loop() {
  potVal = analogRead(A0);
  //potVal = 512; // for testing because I don't have a pot connected

  setHeading(potVal);
}

void setHeading(int potVal)
{
  int index = map(potVal,0,1023,0,N_CHARS);

  for (int i = 0; i < N_CHARS; i++)
  {
    lcd.setCursor(i,0);
    if(index == N_CHARS) index = 0;
    lcd.print(Compass[index++]);
  }
}
917  Using Arduino / Programming Questions / Re: What is: for (uint8_t pin=0; pin<20; ++pin) on: January 27, 2014, 02:16:20 pm
Its equivalent to a BYTE
uint = unsigned integer and 8_t = 0 - 255
918  Using Arduino / Project Guidance / Re: Help on trivia game project on: January 27, 2014, 02:07:22 pm
Quote
I don't have an LCD already,
Ok fine.

The Arduino software has button examples you can play around with, and there are also plenty of other button libraries in the Arduino Playground that you can try.
Same with your servos.

Waiting for a player to press a button and lockout the other player is a little tricky, but we'll get to that later. Right now the best thing you can do is find examples, play with them, learn from them and make your own code. If you have any issues, let us know, but to get help, you must present a code with comments and put some effort into it.
919  Using Arduino / Project Guidance / Re: Help on trivia game project on: January 27, 2014, 01:35:18 pm
Quote
I'm planning on using servos as pointers to represent the score.
?
Why not use a LCD display of some kind?
920  Using Arduino / Project Guidance / Re: Recommendations for game design on: January 27, 2014, 12:38:02 pm
The EasyVR Shield 2.0 can hold up to 32 user- defined trigger words, so if you have 3 categories, then you can only have ten questions each. Selecting a category will change the group of words that must be spoken. Since you want to use a MP3 shield, you can have an array that plays the track and holds the correct answer. If the spoken word matches the answer, then player get a point, not a match, no point. Here is a demo link HERE
921  Using Arduino / Project Guidance / Re: Help on trivia game project on: January 27, 2014, 12:24:32 pm
Will the audio recording be on an MP3 shield or outside unit?

Quote
Pushing the button will lock the other person out.
Is this just one panel or individual panels? Never mind

Quote
If it is correct it will add 1 to the persons score and go to the next question. If it is wrong it will just go to the next question. I am not sure how I will show the score.
This is  really straight forward. Will you be using an LCD display, 7 Segment display, or Serial monitor?

Quote
How should I store and check the answers?
If you use and MP3 Shield, you can use an array to store the track number and correct answer letter/button/pin whatever. If you use an outside unit, then you will need to make sure the correct track is played in order to match it with the correct answer.
922  Using Arduino / Project Guidance / Re: My 1st project: TIE Crawler from the Star Wars Expanded Universe on: January 27, 2014, 09:35:51 am
Well if you want to make it out of Legos, you can still use an Arduino as the brain. This link HERE is my video where I have done just that. It can be controlled via Bluetooth, so I can use a computer, tablet, or android phone to control it. Right now I am using a wireless PS2 controller to control it.

Making it out of Legos, is easy. I was going to suggest you use Lego treads, but since you mentioned you wanted it to look impressive, I scraped the idea.
923  Using Arduino / Programming Questions / Re: Adding buttons to my Simon Says game & general questions. on: January 27, 2014, 04:43:27 am
Play around with mine, change some variables and learn how it works. If you haven't noticed, it is 99% identical to your simon says game. What makes mine different from yours?
924  Using Arduino / Programming Questions / Re: Adding buttons to my Simon Says game & general questions. on: January 26, 2014, 08:33:44 pm
Sorry I didn't respond sooner, busy. Here is my memory game that I think you can learn from, it uses 3 buttons and 3 LEDs.

Code:
/*
  This code is set for buttons to be normally LOW by default.
 To change from normally LOW to HIGH, use "if (buttonState[count] == LOW && buttonState[count] != lastButtonState[count]) "
 */
const byte Num_of_Pins = 3;

byte LEDpin[Num_of_Pins] = {
  5,6,7}; //on-board LED
byte ButtonPin[Num_of_Pins] = {
  2,3,4}; //digital pin 2
byte ledList[32] = {  // renamed to yours
  7,5,6,5};
byte buttonState[Num_of_Pins] = {
  0,0,0};
byte lastButtonState[Num_of_Pins]={
  0,0,0};
byte Pat_count = 4,Btemp = 0;
byte i = 0, output = 0;

int Speed = 300;
int temp = 0, count = 0;

long lastDebounceTime[Num_of_Pins]; 
long debounceDelay = 50;
long time;

boolean PatternStatus = false;
void setup()
{
  randomSeed(A4/A5);
  Serial.begin(9600);
  for(int cnt = 0; cnt < Num_of_Pins; cnt++)
  {
    pinMode(LEDpin[cnt], OUTPUT);
    pinMode(ButtonPin[cnt], INPUT);
  }
}

void loop() {
  showPattern();
  VerifyButtons();
}

void showPattern()
{
  for(byte pattern = 0; pattern < Pat_count; pattern++)
  {
    time = millis();
    while(millis() - time < Speed)
    {
      digitalWrite(ledList[ pattern ], HIGH);
    }
    time = millis();
    while(millis() - time < Speed)
    {
      digitalWrite(ledList[ pattern ], LOW);
    }
  }
}

void updatePattern()
{
  if(Pat_count > 32) Serial.println("Player has won the game");
  else Pat_count++;
  ledList[Pat_count - 1] = random(5, 7);   
}

void VerifyButtons()
{
  i = 0;
  while(i < Pat_count)
  {
    Btemp = Getbutton();
    if(Btemp)
    {
      Serial.println(Btemp);
      if(ledList[i] == (Btemp+Num_of_Pins))
      {
        i++;     
        PatternStatus = true;
      }
      else
      {
        PatternStatus = false;
        break;
      }
    }     
  }
  if(PatternStatus == true)
  {
    Speed -= 9;
    Serial.println("Pattern was Good");
    updatePattern();
  }
  else Serial.println("Player Lost");
}

byte Getbutton()
{
  output = 0;
  for(count = 0; count < Num_of_Pins; count++) // loop through all the buttons
  {
    buttonState[count] = digitalRead(ButtonPin[count]); // read button states
   
    if ((buttonState[count] == HIGH)&&(buttonState[count] != lastButtonState[count])) // check to see if the state has changed from last press
    {
      output = ButtonPin[count];
      lastDebounceTime[count] = millis(); // record the time of the last press
      while((millis() - lastDebounceTime[count]) < 50);
    }
    lastButtonState[count] = buttonState[count];
  }
  return output;
}
925  Using Arduino / Programming Questions / Re: Adding buttons to my Simon Says game & general questions. on: January 26, 2014, 09:39:02 am
Well, you still have 8 hours to learn. I already told you what you had to do after you debounced the buttons, which you could hold of on, but it may give faulty results if you do.

Quote
. . . then you need to cycle through them and compare them to the lit LED. A simple FOR should work. Your buttons are 5 pins lower to your LEDs, so you can start on pin 4 (button) and see if the corresponding LED (+5) is lit. If the LED is lit add the next pattern, if it's not then player has lost.

In this case, you need to cycle through your pattern and see if the correct buttons were pressed. If they were, then add another LED or sequence to your pattern, and if not, then player has lost.
926  Using Arduino / Programming Questions / Re: Adding buttons to my Simon Says game & general questions. on: January 26, 2014, 07:30:13 am
Thankfully I keep all my past sketches.

Code:
/*
  This code is set for buttons to be normally LOW by default.
  To change from normally LOW to HIGH, use "if (buttonState[count] == LOW && buttonState[count] != lastButtonState[count]) "
*/

byte LEDpin[2] = {
  4,5}; //on-board LED
byte ButtonPin[2] = {
  2,3}; //digital pin 2

int buttonState[2];
int last[2];
int lastButtonState[2];

long lastDebounceTime[2]; 
long debounceDelay = 50;

void setup() {
  for(int count = 0; count < 2; count++) {
    pinMode(LEDpin[count], OUTPUT);
    pinMode(ButtonPin[count], INPUT);
  }
}

void loop() {
  for(int count = 0; count < 2; count++) // loop through all the buttons
  {
    buttonState[count] = digitalRead(ButtonPin[count]); // read button states

    if ( buttonState[count] && buttonState[count] != lastButtonState[count]) // check to see if the state has changed from last press
    {
      lastDebounceTime[count] = millis(); // record the time of the last press
      lastButtonState[count] = buttonState[count]; // update last press state
    }

    if ((millis() - lastDebounceTime[count]) > debounceDelay)  // check to see if the desired time has passed
    {
      digitalWrite(LEDpin[count], buttonState[count]); // output results
    }
  }
}
927  Using Arduino / Programming Questions / Re: Midi Input, Led. almost working but not very well :( on: January 26, 2014, 07:09:57 am
Try this one too.

Code:
#define MIDI_CHANNEL 1

byte incomingChannel;    //Read the incoming MIDI channel
byte incomingNote;       //Read the incoming MIDI note
byte incomingVelocity;   //Read the incoming note value
byte LEDs[8]={
  A8,A9,A10,A11,A12,A13,A14,A15};
byte ledStatus[8];


void setup()
{
  Serial.begin (115200);         
  for(byte p = 0; p < 8; p++)
  {
    pinMode(LEDs[p],OUTPUT);
  } 



void loop()
{
  if(Serial.available() > 2)
  {
    incomingChannel = Serial.read();
    incomingNote = Serial.read();
    incomingVelocity = Serial.read();

    if(incomingChannel == MIDI_CHANNEL+143)
    {
      if(incomingNote == 41)
      {
        if(incomingVelocity == 127)
          ledStatus[0] = 1;
        else
          ledStatus[0] = 0;
      }

      if(incomingNote == 42)
      {
        if(incomingVelocity == 127)
          ledStatus[1] = 1;
        else
          ledStatus[1] = 0;
      }
     
      for(byte D = 0; D < 8;D++)
        digitalWrite(LEDs[D],ledStatus[D]);

    }
  }
} //End of loop()


928  Using Arduino / Programming Questions / Re: Midi Input, Led. almost working but not very well :( on: January 26, 2014, 06:49:20 am
There are better codes out there then what you have, that may help you better. Here is a link, CLICK HERE Take a look at the middle example.
929  Using Arduino / Programming Questions / Re: Midi Input, Led. almost working but not very well :( on: January 26, 2014, 06:21:05 am
CTRL + T for starters. Next make it readable.
930  Using Arduino / Programming Questions / Re: Midi Input, Led. almost working but not very well :( on: January 26, 2014, 06:02:31 am
Your code is a train wreck, please fix the format so it looks presentable and possibly readable.
Pages: 1 ... 60 61 [62] 63 64 ... 227