Show Posts
Pages: 1 [2] 3 4 ... 244
16  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 03:00:05 pm
Something like this is all that is needed. Not tested and more is needed to be added in for a full working code. I am not home to complete this, so could someone else finish this? Thank you.

Code:
byte Red=0, Green=0, Blue=0, Counter = 0;

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

void loop()
{
  if(Serial.available() >= 9)
  {
     char Tmp = Serial.read();
     Counter++;
     
     switch( Counter / 3) //changed
     {
         case 0:
              Red = Red * 10 + (Tmp - '0');
              break;
   
         case 1:
              Green = Green * 10 + (Tmp - '0');
              break;

         case 2:
              Blue = Blue * 10 + (Tmp - '0');
              break;
         }
     }
     else
        Counter = 0;

     /* write a piece that resets the colors back to zero for the next sent string */
}
17  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 01:42:47 pm
I wa refering to what I wrote in reply #3 of that link, but if the data IS always 9 characters long then a simple counter and the uses of the module operator will be perfect for your solution.

See if the serial buffer(Serial.available() ) has first collected 9 chars, then once it has read them in one at a time and increment a counter. You can use an array to store the 3 chars and use atoi() to convert the chars into an actual integer. Then using if(counter % 3) you can change to the next variable.

Rinse and repeat.
18  Using Arduino / Programming Questions / Re: Manipulating sequence numbers received through the serial port. on: September 01, 2014, 12:49:54 pm
Is the data consistent, even if you send all zeros?

Try the method in this post Here
19  Using Arduino / Project Guidance / Re: How to programme robot arm positions on: September 01, 2014, 11:55:55 am
Well you can use the Knob example. Use a potentiometer to manually move the servo to where you want it to go, track the position of it with the serial monitor then write down the values of where you think the servo should be.

This method does take some time, especially if you have to move multiple servos, but it works out in the end.

Once you have all the servo(s) positions, write the code that moves the servos when needed.
20  Using Arduino / Programming Questions / Re: Serial.readString() is extremely slow on: September 01, 2014, 02:20:24 am
Not to start anything, just pointing something out for those who read this thread and are just learning about Strings and strings. What you do after looking at the following code is up to you.

Code:
//Uncomment (one at a time) to see the difference in memory used
  //String text = "Hello World"; //  3,518 total bytes -> 1,648 bytes + base line
  //char text[] = "Hello World";// 1,964 total bytes -> 94 bytes + base line
  //char * text = "Hello World";// 1,970 total bytes -> 100 bytes + base line

void setup()
{
  Serial.begin(115200);    //base line 1,870 bytes with next line commented out.          
  Serial.print(text);      // .print('0') -> 1,904 bytes : .print("0") -> 1,954 bytes
}

void loop() { }
21  Using Arduino / Displays / Re: lcd cell count on: September 01, 2014, 12:56:45 am
The screen doesn't give any feedback, so unless you keep track of what you display (using some kind of counter or quite simply an array), there is no way of knowing what is in each cell.
22  Using Arduino / Programming Questions / Re: Merging Bluetooth initializer code with running code on: September 01, 2014, 12:31:54 am
Did you not learn anything from the code I gave you? Yes, I know you are new to this, but if you took the time to actually look and try the code I gave you, you would not be having your issue. (Of which has nothing to do with a missing closing bracket } )

BTW, it should be:
char det = check; // what is check, another variable?
23  Using Arduino / Programming Questions / Re: Merging Bluetooth initializer code with running code on: August 31, 2014, 10:46:08 pm
A loop that doesn't end inside another loop that doesn't end is usually not a good thing, nor needed.

This is your first code.
Code:
#include <SoftwareSerial.h>
#define RxD 3
#define TxD 2

const byte Led = 13;
#define DEBUG_ENABLED  1

// old line: NewSoftSerial blueToothSerial(RxD,TxD);
SoftwareSerial blueToothSerial(RxD,TxD);  
char recvChar; //declared globally. (Can be used throughout the code)

void setup()
{
  Serial.begin(115200); // much faster
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  pinMode(Led, OUTPUT);
  setupBlueToothConnection();
}

void loop()
{
  if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
    recvChar = blueToothSerial.read(); // what you get from here can be used throughout the code.
    Serial.print(recvChar);
  }
  if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
    recvChar  = Serial.read();
    blueToothSerial.print(recvChar);
  }

  if('1' == recvChar)
    digitalWrite(Led, HIGH);
  else if('0' == recvChar)
    digitalWrite(Led, LOW);
}

void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}
24  Using Arduino / Programming Questions / Re: Merging Bluetooth initializer code with running code on: August 31, 2014, 10:08:56 pm
This is not an actual answer to merging your two codes, but it is a cleaner way to gather the data to then control your other stuff.

Are you controlling this from a computer or better yet do you have control of what is being sent?

There is an encapsulation method(packet) that you can try. The sending data needs to be sent in this format < 1, 23, 456, . . . >. Not exactly how I have the values but it needs '<' a comma or some kind of separator and a '>'.

Note: This code convert a string of numeric chars into integers. However if you want to send the data another way, I would like to know.

If this goes over your head, I apologize, I can add in more comments if needed.
Code:
#define SOP '<'
#define EOP '>'
#define SPLIT ",>"

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)
  {
    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
          {
            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, SPLIT);// read the first data index, and store it in a temporary pointer
        buffer[ N_idx ] = atoi(T_holder); // convert the pointer to an integer

        while(T_holder != NULL) // convert the rest of the data until no more data can be read
        {
          N_idx++;
          T_holder = strtok(NULL, SPLIT); // 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 < ... >");
  }
}

void clearBuffer()
{
  while(N_idx !=0)
  {
    buffer[N_idx] = 0; // cleans the buffer for new data.
    N_idx--;
  }
}

If you know exactly what your sending and exactly how many characters, you can reduce the code down more.
25  Using Arduino / Programming Questions / Re: parameter guidelines for display.drawBitmap on: August 31, 2014, 11:07:49 am
Nice.
26  Using Arduino / Programming Questions / Re: Push button timer and LCD readout sketch needed on: August 30, 2014, 09:28:05 pm
Quote
No reply's?  Looks like someone can tell me to figure it out on my own but when I retort, you all get butt hurt.  Nothing like a board with a pos fan base.  Well, skaru you all then, I will do it on my own.  Feel free to take your self righteous god complex and stick it!

I was going to help you and even tell you there is very simple solution to your problem, but after reading that, you can forget it. Who's butt hurt now?

Quote
skaru
smiley-roll?
27  Using Arduino / Project Guidance / Re: small and thin Arduino, which one? on: August 30, 2014, 09:17:57 pm
How much space do you actually have, because an Attiny might work.

Would one of these work? Im not sure of the exact dimensions, but it looks thin enough.
RGB LED surfact mount

If not the first one, then how about this one?
RGB flat LED
28  Using Arduino / Programming Questions / Re: Solved for loop like basic? on: August 30, 2014, 06:04:58 pm
This sounds like the for loops used in Matlab.
[a:b] -> a= start, b = end. It was only given two parameters so by default it increments by 1.

[a:z:b] -> a = start, z=factor(increment by ...), b = end. Three given parameter, increment by factor.

It also has a way to determine whether to increment or decrement by the start and end parameters.


Is this something you're looking for , because you can probably make this a macro? Nope, I tried and it can't  smiley-confuse
29  Using Arduino / Programming Questions / Re: parameter guidelines for display.drawBitmap on: August 30, 2014, 04:02:53 pm
The drawBitmap function is actually from another library called Adafruit_GFX, and the drawBitmap function confuses me too.

If you took a look at the Adafruit_GFX library in a text editor like notepad++, you will be able to see all the functions the library offers.

Quote
drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
What confuses me in this case is the "color", now normally when you draw a bitmap, the color is gotten from the image and just displayed at a certain spot on the display. However, with this function I dont know if the color you set is the background color or not. But I think I may have something you can use.

I made this bitmap function for another user, you can give it a try.
Code:
extern unsigned int conix_64x64[0x1000]; // "conix_[0x1000]" must match the name in the file.

void setup()
{
  /* add in the functions to get your LCD started */
  drawBitmap(0, 0, 64, 64, conix_64x64); // (0,0) where on the screen, (64,64) size of image, (conix_64x64) image name.
}

void loop()
{
}

void drawBitmap(int x, int y, int sx, int sy, unsigned int *data)
{
 int tc = 0;
 for(int Y = 0; Y < sy; Y++)
 {
  for(int X = 0; X < sx; X++)
  {
   display.drawPixel(X+x, Y+y, pgm_read_word(&data[tc]));
   if(tc < (sx*sy)) tc++;
  }
 }
}

To see the image on screen all you need to do is copy and paste the image file below into the same folder of the sketch you are using, it should appear as a new tab. Or copy the contents of the image file(the whole thing) into a new tab (small down arrow in the top right corner of the arduino software) save it then you can use it.
30  Using Arduino / Displays / Re: Touch Screen Library Recommendations? Screen flaishing issues? on: August 30, 2014, 03:21:20 pm
I have an older version you can use just until the website is back up and running again.

I also attached my TFT_Extension library that works with the UTFT and UTouch libraries if your interested in checking it out. Plenty of example sketches to play with and there are 4 games you can try.
Pages: 1 [2] 3 4 ... 244