commit cfccfab7f4c96152263bb933d31fad578e334131 Author: Pippo Date: Mon Jul 2 12:21:02 2018 +0200 first commit diff --git a/NoiseRaw.c b/NoiseRaw.c new file mode 100644 index 0000000..cb0588d --- /dev/null +++ b/NoiseRaw.c @@ -0,0 +1,166 @@ + +/* +------------------------------------------------------------------------ +File : NoiseRaw.c +Project : Gentrop +Version : 1.0.0 +Author : GioDim +Comment : Arduino sketch +History : +24.02.2018 - Release 1.0.0 +------------------------------------------------------------------------ +Copyleft 2018 GioDim + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. +------------------------------------------------------------------------ +*/ + +/* +------------------------------------------------------------------------ +Define +------------------------------------------------------------------------ +*/ + +# define NOISE_PIN 7 +# define BUF_LEN 256 +# define DELAY 2 +# define BAUD_RATE 115200 +# define NUM_BITS 8 + +# define FIRST_BIT 0 +# define SECOND_BIT 1 + +/* +------------------------------------------------------------------------ +Global +------------------------------------------------------------------------ +*/ + +int + Status = FIRST_BIT, + Noise = 0, + Noise_A = 0, + Noise_B = 0, + Bits = 0, + Line = 0; + +uint8_t + Result = 0, + Buf [BUF_LEN]; + +/* +------------------------------------------------------------------------ +Function : setup +Input : +Output : +Comment : +------------------------------------------------------------------------ +*/ + +void setup () +{ + + pinMode (NOISE_PIN, INPUT); + + Serial.begin (BAUD_RATE); + + for (int i = 0; i < BUF_LEN; i++) + Buf [i] = 0; + +} + +/* +------------------------------------------------------------------------ +Function : loop +Input : +Output : +Comment : +------------------------------------------------------------------------ +*/ + +void loop () +{ + + uint8_t + pause = 0; + int + i = 0, + j = 0; + + // Read noise bit + + Noise = digitalRead (NOISE_PIN); + + if (Status == FIRST_BIT) + { + + // First bit + + Noise_A = Noise; + Status = SECOND_BIT; + + } + else + { + + // Second bit + + Noise_B = Noise; + Status = FIRST_BIT; + + // Skip if bits are equal + + if (Noise_A != Noise_B) + { + + // Store bit in byte + + Result <<= 1; + Result |= Noise_A; + + if (++Bits == NUM_BITS) + { + + // Store byte in buffer + + Buf [Line++] = Result; + + if (Line == BUF_LEN) + { + + // Send buffer + + Serial.write (Buf, BUF_LEN); + Line = 0; + + } + + Result = 0; + Bits = 0; + + } + + } + + } + + // Delay loops + + for (i = 0; i < DELAY; i++) + for (j = 0; j < DELAY; j++) + pause++; + +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29