Upload files to ''

Final code for the arduino with i2c connection. LSB to 1 Byte
main
Orell-Pieter Schwarzbach 2023-05-16 11:01:57 +02:00
parent f50640faca
commit 8109013e0b
1 changed files with 50 additions and 0 deletions

50
Arduino_i2c.ino 100644
View File

@ -0,0 +1,50 @@
#include <Wire.h> // 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 */
}