Show Posts
Pages: [1] 2 3 ... 110
1  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: Today at 03:59:31 pm
You've gone back to not using strcmp(). Remember earlier I said you can't compare two c-strings directly like that.

Use:

Code:
if (strcmp(blue,Pblue)){
  //if the two strings aren't the same.
}
2  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 15, 2014, 06:10:02 pm
Ah, see what you mean now.

Yes, as Brad said, you will need your 'value' variable declared as an unsigned long, and also make sure that the getRecievedValue() function has a return type of unsigned long as well.
3  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 15, 2014, 03:46:03 pm
That appears to be doing what it should.

Could you elaborate as to what you are expecting to see?
4  Using Arduino / Programming Questions / Re: Webcam on: April 14, 2014, 01:46:49 pm
OK, let me try again.
16×12×3 = ?

Good news is, we are both wrong smiley-grin

It would only be 10% - I worked it out in bit, not bytes. You on the other hand, no idea where the 3 came from.

But anyway, the point is the same, no... way... in.. hell.
5  Using Arduino / Programming Questions / Re: Webcam on: April 14, 2014, 01:36:37 pm
Quote
16x12pixel frame with 8bit greyscale colour
Pushing aside the uncomfortable concept of grey scale colour, 16×12×3 = 576.
Where does the 75% come from?
'8 bit'... not '8 level'
6  Using Arduino / Programming Questions / Re: Webcam on: April 14, 2014, 01:08:35 pm
Never... Going... To... Happen.

I think you need to do some research on what an 8bit AVR running at 16MHz with only 2k of RAM can actually do.

Just to give you an idea, a 16x12pixel frame with 8bit greyscale colour would consume almost 75% of the RAM of an atmega328.
7  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 14, 2014, 12:09:14 pm
and "sprint(data,"%06d",value);" to "sprintf(data,"%06d",value); "
Sorry about the 'sprint' rather than 'sprintf', IE keeps automatically correcting it as I type.

I believe it is because %d is seeing it as a signed number, try this instead:

Code:
sprintf(data,"%06u",value); //convert 'value' to a string which is padded with 0's to 6 characters. 
8  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 13, 2014, 08:07:56 am
The issues I see:
 (1) you are still using the String class, which won't guarantee that you get 6 characters.
(2) you are not adding a null termination to the 'red', 'blue', and 'green' strings because you have made an uninitialized local copy which shadows the global one which has a null.
(3) you cannot compare c-strings by using the == operator. You have to use strcmp().

Try this:
Code:
RCSwitch mySwitch = RCSwitch();

int ledPinR = 9;
int ledPinG = 10;
int ledPinB = 11;
int Fblue;
char red [3] = {0,0,0};
char blue [3] = {0,0,0};
char green [3] = {0,0,0};
char Pred [3] = {0,0,0};
char Pblue [3] = {0,0,0};
char Pgreen [3] = {0,0,0};
String str;


void setup() {
  pinMode(ledPinR, OUTPUT);
  pinMode(ledPinG, OUTPUT);
  pinMode(ledPinB, OUTPUT);
  
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  Serial.println("Setup was succesfull");
}

void loop() {
  if (mySwitch.available()) {
    Serial.println("mySwitch is available");
    unsigned int value = mySwitch.getReceivedValue();
    char data [7];
    sprintf(data,"%06d",value); //convert 'value' to a string which is padded with 0's to 6 characters.
    Serial.print("This is data, it should contain 6 numbers:");
    Serial.println(data);
    memcpy(red,data+0,2); //copy 2 bytes starting from data[0]
    memcpy(blue,data+2,2); //copy 2 bytes starting from data[2]
    memcpy(green,data+4,2); //copy 2 bytes starting from data[4]
    Serial.print(blue);
    if (strcmp(blue,Pblue)) {
      Serial.print("This is blue, it is an char and should contain 2 numbers:");
      Serial.println(blue);
      Fblue = atoi(blue);
      Serial.print("This is Fblue, it is an int and should contain 2 numbers:");
      Serial.println(Fblue);
     analogWrite(ledPinB, Fblue);
     // Pblue = Fblue incompatible types in assignment of 'int' to 'char [3]
     strcpy (Pblue,blue);
     Serial.println(Pblue);
    }
    
    mySwitch.resetAvailable();
    Serial.println("Available is reseted");
    }
    

}
9  Using Arduino / General Electronics / Re: can anybody tell me the gain of this transistor for 0.15 amp collector current? on: April 12, 2014, 02:53:56 pm
the gain is required for collector current = 0.15 amp and collector-emitter voltage of 12v.
You really want to dissipate 1.8W in your transistor? That does seem rather wasteful.

What are you trying to make?
10  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 09, 2014, 11:14:21 am
It depends how you want them split. If it just in thirds, you can do something simple like:

Code:
char data [9] = {1,2,3,4,5,6,7,8,9};
char left [3];
char mid [3];
char right [3];
memcpy( left,data+0,3); //copy 3 bytes starting from data[0]
memcpy(  mid,data+3,3); //copy 3 bytes starting from data[3]
memcpy(right,data+6,3); //copy 3 bytes starting from data[6]
11  Using Arduino / Microcontrollers / Re: Issues with attiny 85 and 32 KHZ clock crystal on: April 08, 2014, 01:39:52 am
Did you read Datasheet? You can use ONLY 16MHz Crystal oscillator.

Utter nonsense. See Page 164:
12  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 08, 2014, 01:35:25 am
No, its not required to be a compile time constant for arrays.
Code:
void someFunc( int n ){
  
  int arr[ n ];
  Serial.println( sizeof( arr ) / sizeof( *arr ) );
}
//...
someFunc( random( 1, 30 ) );


But in that situation, the size is known at compile time - it is know to be: sizeof(int)*n - of course it is known, otherwise it wouldn't be able to do malloc() for the array. Clearly during execution it has to do that multiplication.


Code:
typedef int arr_t[ 10 ];

And that one is definitely known at compile time as sizeof(arr_t) is a type. Doing that is no different from passing an array to a function defined as:
void someFunc (int array[10]);

In fact if you were to do this the size ceases to be known:
Code:
void someOtherFunc(int* arr){
  sizeof(arr); //=sizeof(pointer)
}
arr_t array = {1,2,3,4,5,6,7,8,9,0};
someOtherFunc((int*)array_t);
13  Using Arduino / Programming Questions / Re: SPI at 2.500kHz? on: April 07, 2014, 05:41:52 pm
No, you can't divide by 6.4

There are only a set number of divisors which can be found by looking at either the SPI.h file or the datasheet.

You won't be able to divide down to 2.5kHz from 16MHz. For something that slow you are best doing bit-banging.
14  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 07, 2014, 05:40:09 pm
Google "char array c++". You will instantly (first result) find an explanation of what a char array is.
Then google sscanf. The first result is an explanation and sample code of how to use the function.

Ditch the "String" class and use char arrays.
15  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 07, 2014, 05:31:26 pm
the size of a pointer is 4bytes (I'm assuming you are using a Due or something like if you got sizeof(int)=4).

sizeof() is not so much a function as it is a way of getting a "compile time" constant value of a size of an object in bytes.

You cannot use sizeof() in a function to get the size of an array passed to that function because at compile time the size isn't known - think about it, if you pass an array with 10 elements, then pass another array of 40 elements, how can the value of sizeof() be known at the time of compiling, and how if it is compiled in to the code can it change value during execution.

If you were to do this:

void someFunc(int array[10]){
}

Then sizeof(array) = 10 * sizeof(int). This is because you are specifying that the function can only take arrays of 10 integers - not 9, not 11, not 5232342.
Pages: [1] 2 3 ... 110