Hello,
I complied this code fine but I got a warning: invalid conversion from 'byte ()(unsigned int) {aka unsigned char ()(unsigned int)}' to 'char' at temp=EEPROM_read*;*
I don't understand why
```
*#define MPU6050_address_R 0b1100101
#define MPU6050_address_W 0b1100100
String key;
String address;
int array_length=0;
char temp;
byte convert_address;
char key_array[16];
char placeholder[128]; //hold the values from eeprom
char message_array[128]; //set maximum length
char encrypt_array[128]; //encrypted results
void setup() {
// put your setup code here, to run once:
initI2C(100000);
Serial.begin(9600);
set_key();
set_message();
}
void loop() {
if(TWCR &=~(1<<TWEN)){ //turn power off
}
else {
set_message();
}
}
void set_key(){
Serial.println("Please enter a 16 character key:");
while (Serial.available() == 0) {} //wait for serial terminal to be ready
key = Serial.readString();
Serial.print("Your key is: "); //just to verify it was read correctly
Serial.println(key) ;
key.toCharArray(key_array, 16);
for(int i=0; i<128;i+16){
for(int j=0;j<16;j++){
EEPROM_write(i+j,key_array[j]);
}
}
}
void set_message(){
Serial.println("Please enter a peripheral address in the range 0 - 127");
while(Serial.available()==0){}
int val = Serial.parseInt(); //read int
Serial.print("Your entered your address is");
Serial.println(val) ;
Serial.println("Enter your message:");
while(Serial.available()>0){
temp = Serial.read();
message_array[array_length]=temp;
array_length++;
}
Serial.print("Your message is: ");
for(int i=0;i<array_length;i++){
Serial.println(message_array[i]) ;
}
encryption(message_array,array_length); //encryption function
i2cStart(); //start
i2cSend(MPU6050_address_W);
i2cSend(val);
for(int i=0; i<array_length; i++){
i2cSend(encrypt_array[i]);
}
i2cStop(); //Stop
}
void encryption(char message_array[ ],int array_length){
char temp;
int limit=ceil(array_length/16); //if array_length=22 , limit=2
for(int i=0;i<limit;i++){
for (int j=0; j<16; j++) {
temp=EEPROM_read[i];
placeholder[j+(16*i)]=temp;
}
}
for(int j=0;j<array_length;j++){
encrypt_array[j] = message_array[j] ^ placeholder[j]; //XOR
if(encrypt_array[j]==0x00) encrypt_array[j]==0xFF;
}
}
byte EEPROM_read(unsigned int address) {
while(EECR & 0b00000010){}
EEAR=address; //location
EECR |=0b00000001;
return EEDR;
}
void EEPROM_write(unsigned int address, char data) {
while(EECR & 0b00000010){}
EEAR=address; //location
EEDR=data;
cli();
EECR |=0b00000100;
EECR |=0b00000010; //start write
sei();
}
void initI2C(unsigned long bit_rate) {
TWBR =((16000000/bit_rate)-16)/2;
TWCR |=0b00000100;
DDRC &= 0b11001111;
PORTC |=0b00110000;
}
void i2cWaitForComplete(void) {
while(!(TWCR & 0x80)){};
}
void i2cStart(void){
TWCR =0b10100100;
i2cWaitForComplete();
}
void i2cStop(void){
TWCR=0b10010100;
}
void i2cSend(byte data){
TWCR = 0b10000100;
TWDR = data;
i2cWaitForComplete();
}
byte i2cReadAck(void) {
TWCR = 0b11000100;
i2cWaitForComplete();
return TWDR;
}
byte i2cReadNoAck(void){
TWCR = 0b10000100;
i2cWaitForComplete();
return TWDR;
}*
```