Show Posts
Pages: 1 [2] 3 4 ... 231
16  Using Arduino / Project Guidance / Re: Bluetooth with multiple slaves on: July 29, 2014, 02:16:13 pm
Added:
What are trying to do, to where you need multiple slave modules to one Master?

Bluetooth is usually a one-to-one connection. Some can connect to multiple slaves, but they are very expensive. Can you use RF modules instead, you can have as many receivers as you need.
17  Using Arduino / Project Guidance / Re: Arduino unresponsive after a long time on: July 29, 2014, 02:13:23 pm
Post the full code as an attachment or in code tags (The # symbol above the smiley face) [ code ]...[/ code ]
18  Using Arduino / Programming Questions / Re: Multiple rgb led and switch change on: July 29, 2014, 02:05:00 pm
The stuff in your loop() function doesn't make sense. Why would you first see if the button is high, then see if it changed? If the button is HIGH and there is nothing within that IF statement to say otherwise, then it will always be HIGH.

Try this, Just replace your loop function with this.
Code:
void loop()
{
  check_switches();
  if (lastState[0] != buttonpressed[0])  // check for state change
  {
    if(buttonpressed[0]) // if button state is HIGH, then do something
    {
      state[0]++;
      if (state[0] > 1)
      {
        state[0] = 0;
      }
    }
    lastState[0] = buttonpressed[0]; // update lastState
  }
  if (state[0] == 0)
  {
    square1();
  }

  else if (state[0] == 1)
  {
    square1solid();
  }
  if (lastState[1] != buttonpressed[1])
  {
    if(buttonpressed[1])
    {
      state[1]++;
      if (state[1] > 1)
      {
        state[1] = 0;
      }
    }
    lastState[1] = buttonpressed[1];
  }
  if (state[1] == 0)
  {
    square2();
  }

  else if (state[1] == 1)
  {
    square2solid();
  }
}
19  Using Arduino / Project Guidance / Re: gamepad with best analog stick? on: July 29, 2014, 01:10:02 pm
No,
Ps2 and Xbox: 1 byte resolution (0 - 255)
Wii classic controller: (0 - 32) range

Added:
If you want a 2 byte resolution, you can multiply the current joystick range by 4, which will put you in the 0 - 1023 range, but it will be choppy. If you want smoother increments, then you would need to make the controller yourself.
20  Using Arduino / Project Guidance / Re: gamepad with best analog stick? on: July 29, 2014, 12:21:14 pm
The PS2 controller already maps the joystick to 0 - 255 internally, but if you want a range of say, 0 - 1023, then you will need to make your own and use the Arduino's analog pins.
21  Using Arduino / Project Guidance / Re: Button Debounce on: July 29, 2014, 12:18:58 pm
Great.
22  Using Arduino / Project Guidance / Re: Button Debounce on: July 29, 2014, 10:57:49 am
Please post a schematic and pictures.

Sounds like you don't have a pulling (pull up or pull down) resistor, so the pin is basically floating until the button is pressed.
23  Using Arduino / Project Guidance / Re: Button Debounce on: July 29, 2014, 09:20:20 am
This is ehh...Ok, there is a better way, but for now, its ok.
Quote
bcurrent = digitalRead(switch1);
    if (bcurrent != LOW)
    {
      delay(5);
      bcurrent = digitalRead(switch1);
    }
    return bcurrent;

This however is not.
Quote
if (track1 == HIGH)
    {
      ledtrack = !ledtrack;
      digitalWrite(led1, ledtrack);
      bcurrent = LOW;
    }
Assuming you want to make a latch, press once do something, press again undo, or do something else, then this part he is wrong.

You don't want to see if it is HIGH all the time, you want to see if it transitions from HIGH to LOW and if that is true AND it is high, then the IF statement is true. Also "bcurrent = LOW;" isn't doing anything.
24  Using Arduino / Programming Questions / Re: How to send and recieve data via 433MHZ module on: July 28, 2014, 08:11:59 pm
Its in the PDF at the bottom.

This is literally all you need, it does both transmit and receive. It couldn't be any simpler.

Bottom of PDF
Quote
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
   Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
//Future Electronics Egypt Ltd. (Arduino Egypt).
 mySerial.begin(4800);
 mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
 mySerial.write(Serial.read());
}
25  Using Arduino / Programming Questions / Re: int to byte conversion on: July 28, 2014, 06:32:39 pm
This is a little closer to what you wanted, conversion-wise, but speed-wise, I'm not sure.

Edit:
Code:
int data[9];
boolean Output[144];
byte counter = 0, i = 0, j = 1, k = 0;
boolean done = false, shown = false;
long time[9];
void setup()
{
  Serial.begin(115200);
  delay(1);
  setArrays();
  showArrays();
  i = 14;
}

void loop()
{
  while(done == false)
  {
    time[k] = micros();
    for(byte counter = 0; counter < 9; counter++)
    {
     Output[i] = bitRead(data[k], counter);
     i++;
    }
    if(k < 9)
      k++;
    else
      done = true;
  }
  showCompletedOutput();
}

void setArrays()
{
  for(byte tmp = 0; tmp < 9; tmp++)
    data[8-tmp] = random(255, 5000);

  for(byte tmp2 = 0; tmp2 < 144; tmp2++)
    Output[tmp2] = 0;
}

void showArrays()
{
  Serial.print("Data: ");
  for(byte tmp = 0; tmp < 9; tmp++)
  {
      Serial.print((data[8-tmp] & 0x1FF), BIN);
      Serial.print("|");
  }
  Serial.println();

  Serial.print("__________Output: ");
  for(byte tmp2 = 0; tmp2 < 72; tmp2++)
    {
      Serial.print(Output[tmp2],BIN);
     if((tmp2 % 8) == 0)
        Serial.print("|");
    }
}

void showCompletedOutput()
{
  if(shown == false)
  {
    Serial.println();
    Serial.print("Completed Output: ");
    for(byte tmp2 = 0; tmp2 < 72; tmp2++)
    {
      Serial.print(Output[71-tmp2],BIN);
      if((tmp2 % 8) == 0)
        Serial.print("|");
    }
    Serial.println();
    for(byte t= 0; t < 9; t++)
    {
      Serial.print(time[t]);
      Serial.print("|");
    }
    shown = true;
  }
}

Quote
Data: 100001011|110001101|1110110|11010|10110011|111101111|111010100|11110|100001000|
__________Output: 0|00000000|00000000|00000000|00000000|00000000|00000000|00000000|00000000|0000000
Completed Output: 0|11000001|10100101|10011111|10111111|10101000|00011110|10000100|00000000|0000000
12704|12732|12760|12792|12820|12848|12884|12912|12944|
26  Using Arduino / Programming Questions / Re: int to byte conversion on: July 28, 2014, 02:00:07 pm
You can give this a shot, I did kinda just threw it together, so if it doesn't work, i'm sorry.

Code:
int data[9];
byte output[12];
byte counter = 0, i = 0, j = 0, k = 0;
boolean done = false, shown = false;

void setup()
{
  Serial.begin(115200);
  delay(1);
  setArrays();
  showArrays();
  i = 7;
}

void loop()
{
  while(done == false)
  {
    for(byte counter = 0; counter < 9; counter++)
    {
      bitWrite(output[j], i, bitRead(data[k], counter));
      i++;
      if(i > 7)
      {
        j++;
        i = 0;
      }
    }
    if(k < 9)
      k++;
    else
      done = true;
  }
  showCompletedOutput();
}

void setArrays()
{
  for(byte tmp = 0; tmp < 9; tmp++)
    data[tmp] = random(255, 5000);

  for(byte tmp2 = 0; tmp2 < 12; tmp2++)
    output[tmp2] = 0;
}

void showArrays()
{
  Serial.print("Data: ");
  for(byte tmp = 0; tmp < 9; tmp++)
  {
    Serial.print(data[tmp]);
    Serial.print(", ");
  }
  Serial.println();

  Serial.print("Output: ");
  for(byte tmp2 = 0; tmp2 < 12; tmp2++)
  {
    Serial.print(output[tmp2]);
    Serial.print(", ");
  }
  Serial.println();
}

void showCompletedOutput()
{
  if(shown == false)
  {
    Serial.print("Completed Output: ");
    for(byte tmp2 = 0; tmp2 < 12; tmp2++)
    {
      Serial.print(output[tmp2]);
      Serial.print(", ");
    }
    Serial.println();
    shown = true;
  }
}

27  Using Arduino / Programming Questions / Re: int to byte conversion on: July 28, 2014, 11:57:00 am
You may need to use an array for the 12 bytes, this way you can use bitRead and the module operator. The first Int gets stored at 0x80 of the first byte, so you will need to start a counter at say 7. Increment that counter from 0 - 8, and use the module operator to increment the index when the counter is 7, to change which byte the int value(bit) gets stored into.

If I had my Nano, with me I could do a test, but unfortunately, I left it home. Sorry.
28  Using Arduino / Programming Questions / Re: A timer that counts down based on how many times a button is pressed on: July 28, 2014, 09:17:15 am
How to debounce a button(wired properly and not floating), how to blink an LED without the uses of the delay() function and how to keep track of time with the millis() function.

All of which are provided under your Arduino Example sketches.

I should also add incrementing and resetting a variable.
29  Using Arduino / Programming Questions / Re: Very strange LED cube error on: July 27, 2014, 12:29:23 am
Other than using more RAM, I don't see anything wrong with the code. You said you were powering the LEDs from the arduino, and that only one was on at a time, right? What about when the cube is fully lit? I still think its the amount of current being drawn which could be the probable issue. That or you have a memory leak somewhere that I don't see.

Code:
int row[4] = {
  A5,A4,A3,A2};
int col[16] = {
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,A0,A1};
int time = 1;
int mtime = 300;
int counter = 5;
#define DEBUG false

//==============================================================
#if false
unsigned int l[160] = {
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  65535,65535,65535,65535,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  1632,65535,65535,1632,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  0,1632,1632,0,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632,
  1632,28662,28662,1632
};
#endif
unsigned int l[444] = {1,0,0,0,3,0,0,0,7,0,0,0,15,0,0,0,143,0,0,0,2191,0,0,0,34959,0,0,0,51343,0,0,0,59535,0,0,0,63631,0,0,0,63887,0,0,0,63903,0,0,0,63935,0,0,0,63999,0,0,0,65023,0,0,0,65535,0,0,0,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535};

//==========================================================

void setup()
{
  for(int i=0;i<16;i++)
    pinMode(col[i],OUTPUT);
#if DEBUG
  Serial.begin(115200);
  delay(1);
  Serial.print("FreeRam remaining: ");
  Serial.println(freeRam());
  Serial.println(sizeof(l) /2);
#endif
}

int freeRam() {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval==0?(int)&__heap_start:(int)__brkval);
}

void loop()
{
  for(int i=0; i < sizeof(l)/2; i += 4)
  {
    for(int q = 0; q < 4 ; q++)
    {
      conv(l[i+q],(i+q) % 4);
      delay(time);
    }
    delay(100);
  }
}

void conv(unsigned int num, int k)
{
  //word w=word(num);
  static unsigned int leder;
  for(int i=15; i >= 0; i--)
  {
    if(bitRead(num,i) != 0)
    {
      leder = (bitRead(num,i) * i + (16 * k));
      #if DEBUG
      bitRead(num,i)? Serial.print("1") : Serial.print("0");
      #endif
      led(leder);
    }
    else
      led(-1);
  }
  #if DEBUG
  Serial.println();
  #endif
}

/*void reset(){
 for(int i=0;i<16;i++){
 digitalWrite(col[i],LOW);
 }
 for(int i=0;i<4;i++){
 pinMode(row[i],INPUT);
 }
 }
 */
 
void led(int leds)
{
  if(leds != -1)
  {
    for(int i=0; i<4; i++)
    {
      if((16*i) <= leds && leds < (16*(i+1)) )
      {
        pinMode(row[i],OUTPUT);
        digitalWrite(row[i],LOW);
      }
    }
    digitalWrite(col[leds % 16],HIGH);
  }
  delayMicroseconds(mtime);

  if(leds != -1)
  {
    for(int i=0; i<4; i++)
      if((16*i) <= leds && leds < (16*(i+1)) )
      {
        pinMode(row[i],INPUT);
      }
    digitalWrite(col[leds % 16],LOW);
  }
}
30  Using Arduino / Programming Questions / Re: Need help with code for autonomous rc car on: July 26, 2014, 04:46:58 pm
Im amazed you never learned what a state machine.

Take a look at the following link.
http://www.perl.com/pub/2004/09/23/graphics/final.jpg
Pages: 1 [2] 3 4 ... 231