Show Posts
Pages: 1 ... 14 15 [16] 17 18 ... 253
226  Using Arduino / Programming Questions / Re: Servos not working/responding, on: August 19, 2014, 03:07:55 pm
Not sure if this should be a new post or not.

How are they powered and wired?
227  Using Arduino / Programming Questions / Re: Software Serial and Servo on: August 19, 2014, 03:04:27 pm
And also take a look at this. ServoTimer2
228  Using Arduino / Programming Questions / Re: const int variable value changes?! on: August 18, 2014, 11:33:24 pm
Because it's type int, which has a value range of -32768 to 32767. Basically once the value goes past 32767, it rolls over into the negatives so 60000 - 65535(double the range) is the value you are seeing. If you make it unsigned long in which case the value range is now 0 to 65535, it won't change. Take a look at the arduino refference page to see all the types.
229  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 09:03:09 pm
This one is better, it will search the buffer for all the strings and show which ones it finds. If it doesn't find anything, it will show "not found".

Code:
char * strings[] = {
  "RED", "GREEN", "BLUE","ORANGE"};
 
byte i = 0, j=0;
unsigned long _startMillis = 0;
char data[20];
int index = 0;
boolean search = false, found = false;
#define arrSize(x) sizeof(x)/sizeof(x[0])

void setup()
{
  Serial.begin(115200);
  clear(20);
  Serial.println(arrSize(strings));
}

void loop()
{
  searchBuff(20);
}

void searchBuff(byte samples)
{
  if(Serial.available() > 0)
  {
    for(int S = 0, tmp; S < samples; S++)
    {
      tmp = Serial.read();
      if(tmp != '\n' || tmp != '\r' || tmp != '\0')
        data[S] = tmp;
      delay(1);
    }
    search = true;
    found = false;
  }
  index = 0;

  if(search)
  {
    j = 0;
    while(j < arrSize(strings))
    {
      for(byte i = 0; i < samples; i++)
      {
        if(data[i] != strings[j][index])
          index = 0; // reset index if any char does not match

        if( data[i] == strings[j][index])
        {
          if(index == strlen(strings[j])-1) // is true if all chars in the target match
          {
            Serial.print("Found ");
            Serial.println(strings[j]);
            index = 0;
            found = true;
            break;
          }
          else
            index++;
        }
      }//end of FOR loop
      if(found)
        search = false;
      j++;
    }// End of WHILE loop
    if(!found)
    {
      Serial.println("not found");
      search = false;
    }
   
    clear(samples);
  }// End of Search
}

void clear(byte samples)
{
  int k = 0;
  while(k < samples)
  {
    data[k] = 0;
    k++;
  }
  search = false;
}
230  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 03:40:15 pm
What now?
The purpose of doing it like this is so the code can have multiple passes through what came in the buffer. Every time you do a Serial.read(), it pops an int out of the buffer until the buffer is empty. If you continue to read from the buffer after it is empty, it will return -1.

It doesn't really matter what is stored as long as the code has a copy of the buffer, even if it is empty (doesn't really serve a point if it is empty though).
231  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 02:28:46 pm
I added the delay because it wasn't collecting everything.

I edited the code.
232  Using Arduino / Programming Questions / Re: sending a word on: August 18, 2014, 01:35:35 pm
Try this code. I have made a smaller version, but it needs a modified version of the HardwareSerial library to work.

It's not pretty, but it works.

Edited: Had to add delay(1) back in, to get it to work correctly.
Code:
char * strings[] = {
  "RED", "GREEN", "BLUE","ORANGE"};
byte i = 0, j=0;
unsigned long _startMillis = 0;
char data[20];
int index = 0;
boolean search = false, found = false;
#define arrSize(x) sizeof(x)/sizeof(x[0])

void setup()
{
  Serial.begin(115200);
  clear(20);
  Serial.println(arrSize(strings)); // shows 4 to indicate the 4 different colors
}

void loop()
{
  searchBuff(20);
}

void clear(byte samples)
{
  int k = 0;
  while(k < samples)
  {
    data[k] = 0;
    k++;
  }
  search = false;
}

void searchBuff(byte samples) // how many samples you want to collect from the buffer to check
{
 if(Serial.available() > 0) // this collects chars from the buffer to cycle through
  {
    for(int S = 0, tmp; S < samples; S++)
    {
      tmp = Serial.read();
      if(tmp != '\n'  || tmp != '\r' || tmp != -1)
        data[S] = tmp;
      delay(1);
    }
    search = true;
    found = false;
  }
  index = 0;

  if(search)
  {
    j = 0;
    while(!found)
    {
      for(byte i = 0; i < samples; i++)
      {
        if(data[i] != strings[j][index])
          index = 0; // reset index if any char does not match

        if( data[i] == strings[j][index]) // if a char does match, see if any more match
        {
          if(index == strlen(strings[j])-1) // return true if all chars in the target match
          {
            Serial.print("Found ");
            Serial.println(strings[j]);
            j = 0; // reset strings index
            index = 0; // reset matched char counter
            clear(samples);
            found = true;
            break;
          }
          index++;
          found = false;
        }
      }
      if( (j >= arrSize(strings)) && !found) // if nothing is found, show "Not found"
      {
        Serial.println("not found");
        j = 0;
        clear(samples);
        break;
      }
      else
        j++;
    }
  }
}
233  Using Arduino / Project Guidance / Re: Animatronic Iron Man Suit Feasibility on: August 18, 2014, 09:53:49 am
There was another person who made a Iron man helmet where the face plate opens and closes. I can't find the post, but i'm sure its here somewhere. Found it, LINK

Anyway, I was thinking maybe you can use a capacitive touch sensor on the outside of the helmet to activate the helmet. Its looks better then a normal button, but then again, anyone can use/touch it. If this is not a problem then give it a try.

The code is simple, the only thing you need to worry about is where your going to fit everything and still make it look good. You might be able to do everything with an ATtiny (which one exactly, im not sure) which will allow you to compact everything into a small space.
234  Using Arduino / Project Guidance / Re: Displaying variable on TFT on: August 17, 2014, 09:04:14 pm
Like Roger, I don't have your hardware either, so I can't do any actual tests.

Your best bet would be to use sprintf().

Code:
void loop()
{
  char str[4]; // you dont need to constantly remake the array, so this line can be put before setup()
  sprintf(str, "%d", analogRead(A9)); // converts the numerical value to a string and stores it in the array.

  Tft.drawString(str,0,160,1,CYAN); // print the array.
}
235  Using Arduino / Project Guidance / Re: Displaying variable on TFT on: August 17, 2014, 07:19:26 pm
It seems to be displaying ascii characters.

Test this to see if the screen shows 123, and if it does, simply replace 123 with map(analogRead(A9), 0, 1023, 0, 100);

Code:
void loop()
{
  char str[4];
  *str = 123;
Tft.drawString(str,0,160,1,CYAN);
}
236  Using Arduino / Project Guidance / Re: Displaying variable on TFT on: August 17, 2014, 06:46:06 pm
char str[0]; basically your not making an array, it should be atleast char str[1].

Try this instead.
Code:
void loop()
{
  int flevel = map(analogRead(A9), 0, 1023, 0, 100);

  Tft.drawChar(flevel,150,0,3, RED);
  delay(1000);
  Tft.drawChar(flevel,150,0,3, BLACK);

}
237  Using Arduino / Project Guidance / Re: Displaying variable on TFT on: August 17, 2014, 06:18:08 pm
Use int instead of char fro storing the value from analogRead().

Also when your using arrays and a function that is looking for a string, you need to use pointers.

Try drawChar instead of drawString, like Tft.drawChar(str[0],0,160,1,CYAN);
238  Using Arduino / Programming Questions / Re: TFT TouchScreen V1.0 seeedstudio !!!HELP ME!!! on: August 16, 2014, 07:48:01 pm
Yea I know, what I highlighted in my last reply is the line in the code you need to change.

Actually, there is another line that also says Main menu, it might be the one you need to change.

Quote
// create the various menus setting the items, font size, spacing, padding, justification and titles
TouchScreenMenu paddingSubMenu = TouchScreenMenu(paddingSubMenuItems, 2, 5, 20, CENTERJ, "Padding");
TouchScreenMenu spacingSubMenu = TouchScreenMenu(spacingSubMenuItems, 2, 40, 5, CENTERJ, "Spacing");
TouchScreenMenu smallSubMenu = TouchScreenMenu(smallSubMenuItems, 1, 10, 5, CENTERJ, "Small Font");
TouchScreenMenu rightSubMenu = TouchScreenMenu(rightSubMenuItems, 2, 10, 5, RIGHTJ, "Right Justify");
TouchScreenMenu leftSubMenu = TouchScreenMenu(leftSubMenuItems, 2, 10, 5, LEFTJ, "Left Justify");
TouchScreenMenu subMenu = TouchScreenMenu(subMenuItems, 2, 10, 5, CENTERJ, "Sub Menu");
TouchScreenMenu mainMenu = TouchScreenMenu(mainMenuItems, 2, 10, 10, CENTERJ, "Main Menu");
239  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 16, 2014, 05:12:36 pm
@robtillaart
I just downloaded version 1.5.7, and I guess the permissions were changed back, because your code doesn't work anymore.

Edit:
I downloaded 1.5.6 r2 and it doesn't work either, I got the exact same error message :/

Error message:
Quote
Arduino: 1.5.7 (Windows 8 ), Board: "Arduino Uno"

In file included from C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/Arduino.h:221:0,
                 from sketch_aug16a.ino:1:
C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/HardwareSerial.h: In function 'void loop()':
C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/HardwareSerial.h:101:51: error: 'unsigned char HardwareSerial::_rx_buffer [64]' is protected
     unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
                                                   ^
sketch_aug16a.ino:9:18: error: within this context
In file included from C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/Arduino.h:221:0,
                 from sketch_aug16a.ino:1:
C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/HardwareSerial.h:93:32: error: 'volatile rx_buffer_index_t HardwareSerial::_rx_buffer_head' is protected
     volatile rx_buffer_index_t _rx_buffer_head;
                                ^
sketch_aug16a.ino:11:18: error: within this context
In file included from C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/Arduino.h:221:0,
                 from sketch_aug16a.ino:1:
C:\Users\Andrew\Documents\arduino-1.5.7\hardware\arduino\avr\cores\arduino/HardwareSerial.h:94:32: error: 'volatile rx_buffer_index_t HardwareSerial::_rx_buffer_tail' is protected
     volatile rx_buffer_index_t _rx_buffer_tail;
                                ^
sketch_aug16a.ino:13:18: error: within this context

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
240  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 16, 2014, 04:20:52 pm
Well if you think about, all we need to do is access the buffer. The only problem that I can't seem to figure out is how to access the buffer

From HardwareSerial.cpp file.
Quote
struct ring_buffer
{
  unsigned char buffer[SERIAL_BUFFER_SIZE];
  volatile unsigned int head;
  volatile unsigned int tail;
};

Is there any way to access this struct outside the library?
Pages: 1 ... 14 15 [16] 17 18 ... 253