danindiana / arduinoGPT

Arduino code generated from OPenAI GPT
1 stars 0 forks source link

smallnet_randomout #2

Open danindiana opened 1 year ago

danindiana commented 1 year ago

C:\Users\walter\Documents\Arduino\sketch_jan24a\sketch_jan24a.ino:11:10: warning: narrowing conversion of 'random(10)' from 'long int' to 'float' inside { } [-Wnarrowing] {random(10)},


C:\Users\walter\Documents\Arduino\sketch_jan24a\sketch_jan24a.ino:12:10: warning: narrowing conversion of 'random(10)' from 'long int' to 'float' inside { } [-Wnarrowing]
   {random(10)},
    ~~~~~~^~~~
C:\Users\walter\Documents\Arduino\sketch_jan24a\sketch_jan24a.ino:13:10: warning: narrowing conversion of 'random(10)' from 'long int' to 'float' inside { } [-Wnarrowing]
   {random(10)}};
    ~~~~~~^~~~
C:\Users\walter\Documents\Arduino\sketch_jan24a\sketch_jan24a.ino: In function 'void loop()':
sketch_jan24a:35:33: error: invalid operands of types 'float' and 'int' to binary 'operator&'
   Serial.println(char(output[0] & 0xFF));
                       ~~~~~~~~~~^~~~~~
exit status 1
invalid operands of types 'float' and 'int' to binary 'operator&'
danindiana commented 1 year ago

Solution: The operators % and & are not defined for floating point datatypes. Try integer datatypes instead.

//Write an extremely minimalist arduino neural network program that correctly compiles and runs on the Atmel 328p microchip. Randomize the weights and generate output of the network for the serial monitor as a series of alphanumeric characters. Define operators % and & as interger datatypes.

include

int weights[3][3] = { {1, 0, 9}, {3, 7, 4}, {2, 8, 5} };

int x[3] = {1, 1, 0}; int sum[3] = {0, 0, 0}; int y[3] = {0, 0, 0};

void setup() { Serial.begin(9600);

for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sum[i] = sum[i] + (x[j] & weights[i][j]); } }

for (int i = 0; i < 3; i++) { y[i] = sum[i] % 2; }

for (int i = 0; i < 3; i++) { Serial.print((char) y[i]); } }

void loop() { //empty }