Show Posts
Pages: 1 ... 44 45 [46] 47 48 ... 229
676  Using Arduino / Programming Questions / Re: Problem debouncing multiple buttons on: March 13, 2014, 12:22:15 am
Something in here is backwards. Adding some spaces may help you find the problem.
Quote
for(int i=0; i>99; i++){
    previousMillis[ i ]=0;
  }
677  Using Arduino / Programming Questions / Re: Trying to run an "If" statement only once on: March 13, 2014, 12:16:35 am
You already wrote the answer to your question in another statement.

Quote
else if (buttonState == 0 && lastButtonState == 1 && blinking == true){ // all three conditions must be TRUE to enter this statement, so what happens if one is initially true, then gets set to false without setting it back to true?
   blinking = false;                                    // turn off blinking, all done timing
   lastButtonState = buttonState;                       // store buttonState in lastButtonState, to compare next time
678  Using Arduino / Project Guidance / Re: LCD with Custom Push Buttons on: March 12, 2014, 06:29:30 pm
Oh so you dont have the Lcd with the buttons, you just have a regular 16x2 Lcd. Well to add the buttons, you would need to write that part in yourself. Pins A0 - A3 should work for your buttons. They can be read in as either digital or analog, just make sure you specify A0 - A3 and not confuse them with pin 0 - 3.

There is a simple test sketch that you can use to test you buttons on those pins. It should be under the Digital examples.
679  Using Arduino / Project Guidance / Re: LCD with Custom Push Buttons on: March 12, 2014, 04:09:35 pm
If I remember correctly, it only uses pin A0 for all six buttons, but if you want to add more, then you should be able to use pins A1 - A4. Don't forget to have resistors for either pulling the pins up to Vcc or pulling them down to Gnd.
680  Using Arduino / Programming Questions / Re: Calling child member from Base/Parent array? on: March 12, 2014, 12:22:00 pm
Beginners always mess with the code to try and understand it. Now will they be smart enough to go into the .h and .cpp files, who's to know.
681  Using Arduino / Project Guidance / Re: Arduino Pro Mini, 3.3V and JY-MCU bluetooth on: March 12, 2014, 04:09:19 am
Quote
Summary

Microcontroller   ATmega168
Operating Voltage   3.3V or 5V (depending on model)
Input Voltage   3.35 -12 V (3.3V model) or 5 - 12 V (5V model)
Digital I/O Pins   14 (of which 6 provide PWM output)
Analog Input Pins   8
DC Current per I/O Pin   40 mA
Flash Memory   16 KB (of which 2 KB used by bootloader)
SRAM   1 KB
EEPROM   512 bytes
Clock Speed   8 MHz (3.3V model) or 16 MHz (5V model)

Use a 5V regulator to power both. A standard 5V regulator circuit should suffice, also make sure you have the correct capacitors too.
682  Using Arduino / Programming Questions / Re: Help with code In return a box of Components as a thank you on: March 12, 2014, 03:54:34 am
This here, is what is causing your numbers to flash.
Quote
for (uint8_t i=0; i<NUMADC; i++) {
      lcd.setCursor(sensors.txtx,sensors.txty);
      lcd.print(sensors.txt);
    }

And this is because of the blank space in your text, in the sensor array, " CPU      ", "  SYS     ", "PARITY   ", " DRIVE   "

To solve this issue, you can add a lockout variable called shown, like so.
Code:
if(!shown) // if this text has not been shown on the display, show it, otherwise skip this part.
  {
    for (uint8_t i=0; i<NUMADC; i++) {
      lcd.setCursor(sensors[i].txtx,sensors[i].txty);
      lcd.print(sensors[i].txt);
    }
    shown = true; // this means the text in already on the display, so set the variable true, to skip this section.
  }

Now this will change when your warning screen is shown, so when the warning screen goes away, you need to set shown back to false, otherwise the code will think the text is already on the screen when it is not.

Add shown = false; here in the warning section.
Quote
for (uint8_t l=0; l<(1000/30); l++)                                        // 1 second silence
      {
        analogWrite(LEDPIN, brightness);                                       // set the brightness of pin 9:
        brightness = brightness + fadeAmount;                                  // change the brightness for next time through the loop:
        if (brightness == 0 || brightness == 255) fadeAmount = -fadeAmount ;   // reverse the direction of the fading at the ends of the fade:
        delay(30);                                                             // wait 30 milliseconds
      }
      shown = false;

Aside from all the delays and the few useless FOR loops, it should work. You could also write the code a whole lot better by taking out all the delays and use IF statements to see if a certain time interval has past. Look into the Blink Without Delay example sketch.
683  Using Arduino / Project Guidance / Re: Help with first project. Code sketch on: March 11, 2014, 05:05:16 pm
Where does "1111 1111 and 0000 0000" come from?

If you want to control your motors using nibbles, then you would need to mask off which nibbles go where.

So for example, 1010 | 0101 -> leftSide | rightSide
data = 10100101  => data >> 4 = 00001010 = leftSide.
-----------------  => data & 0x0F = 00000101 = rightSide.

Now since you want to use the nibbles to control the speed, you would need to multiply the leftSide by 17, because 15 * 17 = 255.
And for rightSide you would either need to subtract 15 from rightSide, then multiply it by 17, or just format the nibble the correct way. Yours is 0101, where it should be 1010 to make things easier.
684  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 11, 2014, 12:39:38 am
Ok, that could easily be changed at the top. But since you want to make the controller yourself, you can make it anything you want.
685  Using Arduino / Programming Questions / Re: Calling child member from Base/Parent array? on: March 10, 2014, 09:23:56 pm
Its called an inheritance. Look at this link HERE. Then go down to Inheritance between classes. You can also look at the next page, Polymorphism.
686  Using Arduino / Displays / Re: Arduino LCD screen on: March 10, 2014, 09:10:39 pm
Which Lcd screen are you referring to, 16x2, 20x4, 128x64, or a certain TFT screen?

A link or a picture of what you have and if you would also post your code, would be really helpful. Otherwise we will just be guessing and getting nowhere fast, or we would simply ignore your thread until more information is provided.

If you decided to post your code, please use code tags [ code ] ... [/ code ]. Look for the # symbol above the smiley faces.
687  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 10, 2014, 09:01:41 pm
SOP(Start of Packet) and EOP(End of Packet) are defined at the top of the code as
Quote
#define SOP '<'
#define EOP '>'

So wherever SOP or EOP are, they get substituted with < or >. The data you need to send in, needs to be formated as such

Example: <123,45,6789>
<1,12345,67,89>
<1,2,3,4,5>

Whatever you send in, will be converted to an integer. You can only enter a value within a range from -32,768 to 32,767, unless coded otherwise.

There is another way to do this without needing to convert anything, and that is with using a structure.

Example:
typedef struct someData
{
  int A;
  long B;
  char C;
  boolean D;
} myData;

You would gather the data then send out a refference to someData. This method is better code wise, but from a test that I did using virtualwire, it wasn't really any faster. I will do more tests on it, but I for right not, you can use what I gave you.

Another thing,  if you know exactly how much data your sending, you can change the 5 in "for(byte i = 0; i < 5; i++)" to however many you want to see back. So if you send 3 ints, you dont need to see 5 values, two of which are zero.
688  Using Arduino / Project Guidance / Re: Help with password on: March 08, 2014, 03:29:24 pm
Well your password sketch does compile, so that's good, but now the issues is, you didn't make it, so you don't really know how it works or how to add in the things you need.

Quote
the whole system is to control the +VCC on ping sensor " ON-OFF Control " i ll attach the VCC pin of the sensor instead off the ledPin as my sensor needs 5v
This can be done but the digital pins can only supply so much current, so you might need to get some NPN transistors or even some opto-couplers in order to control the power to the sensors, if they are not going directly to the 5V line.

Quote
is it possible to make another password to turn it off i mean when i enter 4321 it turns on when i press 5678 turn off ????
Yes it is possible to have multiple passwords. This link HERE is to another post with the same question. Look at reply #21 for a working code. NOTE: that sketch uses 3 passwords.

As for your ping sensors, you may want to download the NewPing library, as it is faster and more precise.
689  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 03:38:15 pm
Buffer sorting example.
Code:
#define SOP '<'
#define EOP '>'

byte idx = 0, N_idx = 0;
boolean convert = false;
char c = NULL;
char * T_holder;
int * tmp = NULL;

#define MAXSIZE 20
char Data[ MAXSIZE ];
int buffer[MAXSIZE];

void setup()
{
  Serial.begin(115200);       
}

void loop()
{
  tmp = getData(); // call the function to collect the incoming data and return a pointer to the collected data
  if(tmp) // make sure something is in there
  {
    for(byte i = 0; i < 5; i++)
      Serial.println(tmp [ i ]);
  }
}

int * getData()
{
  if( Serial.available() > 0)       // if data is available to read
  {
    c = Serial.read(); // read in the first character
    if(c == SOP) // compare that character to <
    {
      idx = 0;
      while( true ) // if the first char equals <, then collect the rest.
      {
        if( Serial.available() > 0) // this is needed again to make sure no junk is collected
        {
          c = Serial.read(); // read in the new chars

          if(c == EOP) // compare char to >
          {
            Data[ idx + 1 ] = EOP; // if char is equal to > then add it to the end of the packet
            convert = true; // tell the code to convert the chars to useable ints
            break; // break out of while loop
          }
          else // if char is NOT equal to >, continue to store them.
          {
            Data[ idx ] = c; // store new char in Data array
          }

          if(idx < MAXSIZE) // check to see the number of incoming chars does not exceed the set maximum
          {
            idx++; // number of char did not exceed the maximum chars allowed
          }
          else
          {
            Serial.println("Input data has exceeded the maximum data allowed.");
            break;
          }
        }
      }
     
      if(convert == true)
      {
        clearBuffer(); // make sure the buffer is clean before adding to it

        T_holder = strtok(Data, ", EOP");// read the first data index, and store it in a temporary pointer
        buffer[ N_idx ] = atoi(T_holder); // convert the pointer to an integer, and store into an index in buffer

        while(T_holder != NULL) // convert the rest of the data until no more data can be read
        {
          N_idx++; // increment new index for next converted data
          T_holder = strtok(NULL, ",>"); // search the data array for a comma, and >
          buffer[ N_idx ] = atoi(T_holder);
        }
        convert = false;
        return buffer; // when all data is converted, return it.
      }
    }
    else Serial.println("Incoming data must be formated as < ... >"); // if the first char is not <, then display error message.
  }
}

void clearBuffer()
{
  while(N_idx !=0)
  {
    buffer[N_idx] = 0; // cleans the buffer for new data.
    N_idx--;
  }
}
690  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 02:42:20 pm
Ok, thankfully I keep all my older sketches.
This code is not using bluetooth, but the only thing that would need to change is how the incoming data is stored into the buf[ ] array.

Most accelerometers are 3 axis, so they send out x,y, and z data. This code is designed to read in a string of data composed of x,y,z and a state/option. This option is what im using to control my gripper claw, but it can be used to toggle between motion and autonomous control.

Code:
/*
  simple control test
*/
 
#include <VirtualWire.h>
int DRV1,DRV2,STRR,STRL;

int x = 0;
int y = 0;
int z = 0;
int s = 0;
char c[30];

int ledpin = 13;
byte Mopen = 4;
byte Mclosed = 2;
byte M1L = 3;// PWM
byte M2L = 5;// PWM
byte M1R = 11;// PWM
byte M2R = 6;// PWM
// LED connected to pin 13 (on-board LED)

void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(Mopen, OUTPUT);                               
  pinMode(Mclosed, OUTPUT);
  pinMode(M1L, OUTPUT);                               
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                               
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 115200bps
 
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(8);
  vw_rx_start();
}

void loop() {
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

   if (vw_get_message(buf, &buflen)) // Non-blocking
   {
     int i;
     // Message with a good checksum received, dump it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++){
           digitalWrite(ledpin, HIGH);
           c[i] = buf[i];
         }
         
        x=atoi(strtok(c,","));
        y=atoi(strtok(NULL,","));
        z=atoi(strtok(NULL,","));
        s=atoi(strtok(NULL," "));
       /* Serial.print(x);
        Serial.print(",");
        Serial.print(y);
        Serial.print(",");
        Serial.print(z);
        Serial.print(",");
        Serial.print(s);
        Serial.println();*/
        move(z, y, s); 
   }
}
   
  void move(int z, int y, int s)
  { 

  //Movement varibles
 
  int DRV2 = map(z, 0, 9, 255, 0);
  int DRV1 = map(z, 10, 20, 0, 255);
  int STRL = map(y, 0, 9, 255, 0);
  int STRR = map(y, 10, 20, 0, 255);
 
  /*
  Serial.println(DRV1);
  Serial.print(",");
  Serial.print(DRV2);
  Serial.print(",");
  Serial.print(STRL);
  Serial.print(",");
  Serial.print(STRR);
  Serial.println();
  */
  if(z > 10)//forwards               
  {
    //Serial.println("Forward with turning");
    analogWrite(M1L, constrain(abs(DRV1 - STRL),0,255)); analogWrite(M1R, constrain(abs(DRV1 - STRR),0,255));   
    digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);   
  }
  else if(z < 9)//backwards               
  {
    //Serial.println("Reverse with turning");
    digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);   
    analogWrite(M2L, constrain(abs(DRV2 - STRL),0,255)); analogWrite(M2R, constrain(abs(DRV2 - STRR),0,255));   
  }
   else if(z < 14 && z > 6 && y > 10)//Right               
  {
    //Serial.println("360 left");
    digitalWrite(M2L, LOW); analogWrite(M2R, STRR);   
    analogWrite(M1L, STRR); digitalWrite(M1R, LOW);
  }
  else if(z < 14 && z > 6 && y < 9)//Left             
  {
     //Serial.println("360 right");
    analogWrite(M2L, STRL); digitalWrite(M2R, LOW);   
    digitalWrite(M1L, LOW); analogWrite(M1R, STRL);   
  }

  else //full stop
  {
    digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);       
    digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);   
  }

   if(s == 1)
    {
      Serial.println("Claw Opening");
      digitalWrite(Mopen, HIGH); digitalWrite(Mclosed, LOW);
    }
    if(s == 2)
    {
      Serial.println("Claw Closing");
      digitalWrite(Mopen, LOW); digitalWrite(Mclosed, HIGH);
    }
    if(s == 0)
    {
      digitalWrite(Mopen, LOW);  digitalWrite(Mclosed, LOW);
    }
   else{
    digitalWrite(ledpin, LOW);
    x=0; y=0; z=0; s=0;
  }
}
Pages: 1 ... 44 45 [46] 47 48 ... 229