51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#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 */
|
|
}
|