Module RF 433 Mhz Library

Hi , i need help please i have code . they work perfect but when i put a the library of Modul RF 433 Mhz #include <RH_ASK.h> .. i don't get the result so where is the problem

#include <RH_ASK.h>
#include <SPI.h>
RH_ASK rf_driver;
float x[10] ;
byte b[160] ;
float a ;
int r = 4 ;
int i ;
int L ;
int bprime[3][3];
int fprime;
char f = 'A' ;
int k1 = 23;
int k2 = 84 ;
int k3=233;
int k4=172;
int vector[9];
void setup() {
  Serial.begin(9600);    
   rf_driver.init();


    x[1]= 0.789632145698;
    for (  int i = 2; i <=10 ; i++) {
      x[i] = r * (x[i-1]*(1 - x[i-1])); 
}
    // partie de binairisation 
   for (  int u = 1; u <= 10 ; u++) {
        a=x[u];
        i=u-1 ;
     for (int k = 1 ; k <= 16; k++){
             if (a>=1/pow(2,k)){
                 a=a-(1/pow(2,k));
                 b[16*i+k]=1 ;
                         }  
                else  {
                a=a;
               b[16*i+k]= 0; 
               //Serial.println(a) ;
                }
          //   Serial.println(b[16*i+k]);   
              }
  } 
// matrix to array 
       for (  int i = 1; i <= 3 ; i++){
              for (int j = 1; j <= 3 ; j++){
               L = i*3+j;
           bprime[i][j]= 2*b[L]+b[L+1];
          //Serial.println(bprime[i][j]);
              }
       }
       
    // cryptage  
          for ( int k = 0 ; k <9  ; k++){
      
                if (vector[k]=0){
                    fprime= f^k1;}             
                   
                 if (vector[k]=1){
                    fprime= f^k3;} 
                      
                 if (vector[k]=2){
                    fprime= f^k2;} 
                    
                 if (vector[k]=3){
                       fprime= f^k4; }
                      }
                      Serial.println(fprime); 
   }
void loop() {

         }

and when i use my code without the library i get the result ... so this is the code without library


float x[10] ;
byte b[160] ;
float a ;
int r = 4 ;
int i ;
int L ;
int bprime[3][3];
int fprime;
char f = 'A' ;
int k1 = 23;
int k2 = 84 ;
int k3=233;
int k4=172;
int vector[9];
void setup() {
  Serial.begin(9600);    
   


    x[1]= 0.789632145698;
    for (  int i = 2; i <=10 ; i++) {
      x[i] = r * (x[i-1]*(1 - x[i-1])); 
}
    // partie de binairisation 
   for (  int u = 1; u <= 10 ; u++) {
        a=x[u];
        i=u-1 ;
     for (int k = 1 ; k <= 16; k++){
             if (a>=1/pow(2,k)){
                 a=a-(1/pow(2,k));
                 b[16*i+k]=1 ;
                         }  
                else  {
                a=a;
               b[16*i+k]= 0; 
               //Serial.println(a) ;
                }
          //   Serial.println(b[16*i+k]);   
              }
  } 
// matrix to array 
       for (  int i = 1; i <= 3 ; i++){
              for (int j = 1; j <= 3 ; j++){
               L = i*3+j;
           bprime[i][j]= 2*b[L]+b[L+1];
          //Serial.println(bprime[i][j]);
              }
       }
       
    // cryptage  
          for ( int k = 0 ; k <9  ; k++){
      
                if (vector[k]=0){
                    fprime= f^k1;}             
                   
                 if (vector[k]=1){
                    fprime= f^k3;} 
                      
                 if (vector[k]=2){
                    fprime= f^k2;} 
                    
                 if (vector[k]=3){
                       fprime= f^k4; }
                      }
                      Serial.println(fprime); 
   }
void loop() {

         }

And this is the result of my code

int bprime[3][3];

...
...
// matrix to array 
       for (  int i = 1; i <= 3 ; i++){
              for (int j = 1; j <= 3 ; j++){
               L = i*3+j;
           bprime[i][j]= 2*b[L]+b[L+1];
          //Serial.println(bprime[i][j]);
              }
       }

Oops

 for (  int i = 2; i <=10 ; i++) {
      x[i]

Also oops

// matrix to array  

Comment is just wrong

I mostly ignore comments.
There are bigger problems.

(Five days ago I suggested you sorted out your understanding of arrays and their indices)

so what !

So, x[10] doesn't belong to you.

yes thank you I remember ... but the code give the right result .. the same result in matlab and the same in python

But you don't own that memory.
It's not yours to write to.
Same with bprime.

Until you fix your array accesses, nothing can be taken at face value.

X[10] It is an array of 10 elements.. my teacher forced me to use it He said x[10] in order to save the results for the next operation as an array of 10 elements

the next operation is

for (  int i = 2; i <=10 ; i++) {
      x[i] = r * (x[i-1]*(1 - x[i-1])); 
}

And they are numbered x[0] to x[9], so x[10] is memory outside of that allocated for the array.

ok thank you i changed it to x[9] because i start from 2 to 10 and i need 9 elements

Could you maybe involve your teacher in the discussion about bprime?
It is possible that s/he doesn't understand the issues here either.

I wish but I can't...they give me the algorithm and went and didn't reply in my emails so.. I asked helpe :sweat_smile: :sweat_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.