From e69720ff46046aa777887eb497c97f90cfe6e421 Mon Sep 17 00:00:00 2001 From: Orell-Pieter Schwarzbach <2122623@stud.hs-mannheim.de> Date: Tue, 16 May 2023 11:57:49 +0200 Subject: [PATCH] Update 'Old_Code/Arduino_i2c.ino' --- Arduino_i2c.ino => Old_Code/Arduino_i2c.ino | 100 ++++++++++---------- 1 file changed, 50 insertions(+), 50 deletions(-) rename Arduino_i2c.ino => Old_Code/Arduino_i2c.ino (95%) diff --git a/Arduino_i2c.ino b/Old_Code/Arduino_i2c.ino similarity index 95% rename from Arduino_i2c.ino rename to Old_Code/Arduino_i2c.ino index b766c34..602310c 100644 --- a/Arduino_i2c.ino +++ b/Old_Code/Arduino_i2c.ino @@ -1,50 +1,50 @@ -#include // I2C-Headerdatei - -const int adcPin = A0; // ADC-Pin -//const int toggleDelay = 0.1; // Verzögerung zwischen dem Umschalten der Bits, in Mikrosekunden -const int bufferSize = 8 * sizeof(uint32_t); - -void setup() { - Wire.begin(8); // I2C-Verbindung initialisieren - analogReadResolution(12); - //Serial.begin(9600); - - //Wire.onReceive(receiveData); - //Wire.onRequest(sendData); - -} - -/*void sendData() { - Wire.write(0xFF); - Serial.write(0xFF); -} - -void receiveData(int count) { - Serial.write('r'); -}*/ - -void loop() { - uint32_t buffer[8] = {0}; - uint8_t bitCount = 0; - - for (int i = 0; i < 8; i++) { - uint32_t randomValue = 0; - - while (bitCount < 32) { - uint16_t adcValue = analogRead(adcPin); - uint32_t newBit = adcValue & 0x01; - randomValue = (randomValue << 1) | newBit; - bitCount++; - //delay(toggleDelay); - } - - buffer[i] = randomValue; - bitCount = 0; - } - - Wire.beginTransmission(8); // I2C-Übertragung an Geräteadresse 8 starten - for (int i = 0; i < 8; i++) { - Wire.write((byte*)&buffer[i], sizeof(buffer[i])); // Daten über I2C-Bus senden - } - Wire.endTransmission(); // I2C-Übertragung beenden */ -} +#include // I2C-Headerdatei + +const int adcPin = A0; // ADC-Pin +//const int toggleDelay = 0.1; // Verzögerung zwischen dem Umschalten der Bits, in Mikrosekunden +const int bufferSize = 8 * sizeof(uint32_t); + +void setup() { + Wire.begin(8); // I2C-Verbindung initialisieren + analogReadResolution(12); + //Serial.begin(9600); + + //Wire.onReceive(receiveData); + //Wire.onRequest(sendData); + +} + +/*void sendData() { + Wire.write(0xFF); + Serial.write(0xFF); +} + +void receiveData(int count) { + Serial.write('r'); +}*/ + +void loop() { + uint32_t buffer[8] = {0}; + uint8_t bitCount = 0; + + for (int i = 0; i < 8; i++) { + uint32_t randomValue = 0; + + while (bitCount < 32) { + uint16_t adcValue = analogRead(adcPin); + uint32_t newBit = adcValue & 0x01; + randomValue = (randomValue << 1) | newBit; + bitCount++; + //delay(toggleDelay); + } + + buffer[i] = randomValue; + bitCount = 0; + } + + Wire.beginTransmission(8); // I2C-Übertragung an Geräteadresse 8 starten + for (int i = 0; i < 8; i++) { + Wire.write((byte*)&buffer[i], sizeof(buffer[i])); // Daten über I2C-Bus senden + } + Wire.endTransmission(); // I2C-Übertragung beenden */ +}