Serial Data Storage

Hello all,
I'm new to Arduino and am using a 5V trinket for an encryption microprocessor. I am reading data from a central HUB that's sending data via wire. First question from the IDE do I read in the data using "analogRead" or "digitalRead"? Second I want to store that data, (an 8 bit serial data number), and xor the number with an a preset key I have already made. Take that output and make it an "analogWrite" to a FM Tx circuit. Was wonder how I would approach this? Seems like using the flash memory to store the 8 bits then pull from it to create the binary number ?

Thanks
P.S. I know my code isn't complete and still has errors when compiled

Tx_encryption.ino (1.44 KB)

int unlock = 165; //"10100101" in binary, these are the keys the signal needs to have to pass through the system from the HUB
int lock = 170; //"10101010" in binary

int key1 = 225; //"11100001" in binary
int key2 = 35; //"00100011" in binary
int data_in = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

data_in = analogRead(3); //reads input serial data from HUB
data_stored = HELP Please; // stores the data in value from here and enter the XOR process

switch (data_stored)
{
case 1{
if (data_stored == unlock){
xor1 = unlock ^ key1; //xor twice for "security"
xor2 = xor1 ^ key2;
analogWrite(4,xor2);
}
break;
} //end case 1
case 2{
if (data_stored == lock){
xor1 = lock ^ key1;
xor2 = xor1 ^ key2;
analogWrite(4,xor2);
}
break;
} //end case 2

default:
break;
}

}

Please edit the code in your reply #1

Type [code] before the code.
Type [/code] after the code

So your code looks likeyour code here

At least one reason why your code does not compile is the missing colon after the cases
Change case 1{
To case 1:{

Do this for all your cases.

nepjr32:
I am reading data from a central HUB that's sending data via wire. First question from the IDE do I read in the data using "analogRead" or "digitalRead"?

What is that HUB?

And what kind of 'wire'?

code
int unlock = 165; //"10100101" in binary, these are the keys the signal needs to have to pass through the system from the HUB
int lock = 170; //"10101010" in binary

int key1 = 225; //"11100001" in binary
int key2 = 35; //"00100011" in binary
int data_in = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

data_in = analogRead(3); //reads input serial data from HUB
data_stored = HELP Please; // stores the data in value from here and enter the XOR process

switch (data_stored)
{
case 1:{
if (data_stored == unlock){
xor1 = unlock ^ key1; //xor twice for "security"
xor2 = xor1 ^ key2;
analogWrite(4,xor2);
}
break;
} //end case 1
case 2:{
if (data_stored == lock){
xor1 = lock ^ key1;
xor2 = xor1 ^ key2;
analogWrite(4,xor2);
}
break;
} //end case 2

default:
break;
}

}
/code

the HUB is :

the wire is the bread board jumper wire from arduino store.

the HUB is :
Terasic - SoC Platform - Cyclone - SoCKit - the Development Kit for New SoC Device

Thanks for the link.

the wire is the bread board jumper wire from arduino store.

That's not what I meant by 'what kind of wire' :wink: What kind of communication is going over that wire. Your title suggests UART communication (startbit, databits, parity, stopbit) and if that is the case your wire should be connected to the (a) RX pin of the Trinket.
I'm not familiar with the ATtiny85 that is used on the Trinket so I'm not sure if it has a complete UART; most (possiblly all) links I found refer to SoftwareSerial which implies that you can use a form of Serial.read().

If it's not a UART, you will have to tell us what kind of protocol you're using (what comes out of the HUB)?

PS
You have to literally use
** **[code]** **
and
** **[/code]** **
; including the square brackets :wink: