Show Posts
Pages: [1] 2 3 ... 110
1  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 21, 2014, 03:09:30 pm
Why did the sprintf line change back??
Code:
sprintf(data,"%06ld",value);

The 06 is what does the padding with 0's
2  Using Arduino / Programming Questions / Re: Webcam on: April 17, 2014, 01:24:27 pm
LAN = Local Area Network
WLAN = Wireless Local Area Network = Wireless LAN = Wi-Fi

If you have a Wi-Fi enabled IP Camera, you can connect it wirelessly to a MiFi module which is in turn connected to the cellular network.

3  Using Arduino / Programming Questions / Re: Webcam on: April 17, 2014, 06:03:13 am
omg... google it.
First result:
"A MiFi device can be connected to a cellular network and provide internet access for up to ten devices" (http://en.wikipedia.org/wiki/MiFi)
4  Using Arduino / Programming Questions / Re: Sscanf ruins my code :( on: April 16, 2014, 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.
}
5  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.
6  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?
7  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.
8  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'
9  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.
10  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. 
11  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");
    }
    

}
12  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?
13  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]
14  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:
15  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);
Pages: [1] 2 3 ... 110