yes i have and im not really getting anywhere sorry to say
AWOL:
You need to read all the input, then compare your two arrays a byte at a time
If you show your tries, tell what you expect and what you get instead, you sure get more specific hints.
I hope no one will do that school project for you ![]()
im not wanting anyone to do it for me just a lil help understanding what im not doing right....
i got this to compile and upload but wont light my led for either conditon and the only value that changes on the incoming bytes is the 6th place value..
#include <NewSoftSerial.h>
#include <string.h>
NewSoftSerial fdk(2, 3);
const int led = 13;
byte array1[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x13, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array2[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x12, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array3[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x11, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array4[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x10, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
void setup()
{
Serial.begin(9600);
fdk.begin(9600);
}
void loop()
{
if (fdk.read()== array1[6])
{
digitalWrite(13,HIGH);
}
else
digitalWrite(12,HIGH);
No, you really need to go back to basics and check how to read a sequence (hint) of bytes from a serial port.
you use the code
if (fdk.available() > 0){
incomingByte = fdk.read();
to do that correct?? and then i need to create an array to put that in correct or can i just compare it to my array i have made already
This reads 1 byte ( starting with the 0xFF, probably ). The other bytes will arrive later
The loop() function typically was run a couple of times, not doing anything special .
You either do nothing until all expected bytes have arrived ( fdk.available() >= 11) and then read them, using a little for ( ) { } sequence into an array,
or you read them as they arrive and "remember" in a global or static variable, where in the sequence you are.
With that position variable, you can immediately check if the read byte is the expected one at that position.
ok michael, something kinda like this with the for loop
[code if (fdk.available() >=11 ){
for(i=0; i<11;i++){
incomingByte[i] = fdk.read();]
i hope this is closer than i have been....only problem is when i use it in the full sketch as followes i get error 'i' was not declared in this scope in the loop
#include <NewSoftSerial.h>
#include <string.h>
NewSoftSerial fdk(2, 3);
int ledPin = 13;
char incomingByte[11];
byte array1[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x13, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array2[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x10, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array3[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x12, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array4[]={0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x11, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
void setup()
{
Serial.begin(9600);
fdk.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
}
void loop()
{
if (fdk.available() >=11 )
{
for(i=0; i<11;i++){}
{
incomingByte[i] = fdk.read();
}
}
}
as you know i want the incoming serial in an array so i can compare one value of the data for a match
So, where did you declare i to be a variable? I don't see that you did.
for(int i=0; i<11; i++)
you are correct paul i guess i did not declare it......so i guess ill do that...but should i declare it as an int or char seing as its a hex value or would it be a byte
but should i declare it as an int or char seing as its a hex value or would it be a byte
0 is not a hex value. 11 is not a hex value. The range of values that i can have would fit in a byte, so you could use byte. char is not appropriate. The array index is not a character.
Thx paul much appreciated
ok i changed char incomingByte[11] to byte incomingByte[11] was that correct..? and i also changed my for statement to
for(byte i=0; i<11;i++){}
{
incomingByte = fdk.read();
}
}
now the only error im getting is that incompatible types in assignment of int to byte[11]
Yes, that's quite an understandable error.
Which element of the array did you want to put the most recently-read character?
I want the bits to go from 0 to 11 in the order they are read i think so i only have to compare the 5th spot in the array and once it fills that spot and gets its match or no match its goes on and sets a pin high as well as other things
No, you want the bytes that go from zero to ten
ok so how do i get them and where is my mistake at ive seen lots of other code that has done what im trying to do and still cant figure out where im making my mistake at my teacher i had for programming has no clue at all so im stuck in the proverbial mud here....im learninng more here than i did in class and would love to have that lightbulb moment....
Reply #26 looked to be going in the right direction, it was just missing a declaration of an index.
ok what do you mean by a decleration of an index? what should i be indexing??? or where should i be indexing...
The index is "i", and you didin't declare it.
wow i just got it to compile.....heres what it looks like now
#include <NewSoftSerial.h>
#include <string.h>
NewSoftSerial fdk(2, 3);
int ledPin = 13;
byte incomingByte[10];
byte array1[]={
0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x13, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array2[]={
0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x10, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array3[]={
0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x12, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
byte array4[]={
0xFF, 0xFF, 0xFF, 0xF5, 0xC0, 0x11, 0x0E, 0xFF, 0xFF, 0xFF, 0xF5};
void setup()
{
Serial.begin(9600);
fdk.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
}
void loop()
{
if (fdk.available() >=10 )
{
for(byte i=0; i<10;i++){
}
{
incomingByte[10] = fdk.read();
}
}
if(incomingByte[5]==array1[5])
{
digitalWrite(13,HIGH);
}
}
as you can see on on the line incomingByte[10] = fdk.read(); i added my array value.....and thats what allowed it to compile. is that the index you was talkin about awol? if so then i see what you was getting at.... but when i uploaded it all i got was an autoscrolling F in my serial monitor after i added the serial.print command....