-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodigo_Arduino.ino
57 lines (53 loc) · 1.13 KB
/
Codigo_Arduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <SoftwareSerial.h>
#include <TimerThree.h>
SoftwareSerial blue(10, 11);
#define BUFFER_SIZE 10
int adcValue;
int bufferM[BUFFER_SIZE];
bool bufferFlag = false;
bool sendFlag = false;
void setup() {
pinMode(A0, INPUT);
Serial.begin(9600);
blue.begin(9600);
EICRA &= ~(1 << ISC01);
Timer3.initialize(1000);
Timer3.attachInterrupt(Muestreo);
}
void loop(){
static unsigned int pos = 0;
if (blue.available()) {
char signal = blue.read();
Serial.println(signal);
if (signal == '1')
{
sendFlag = true;
} else if(signal != '1'){
sendFlag = false;
}
}
if(EICRA & (1 << ISC01)){
bufferM[pos] = analogRead(A0);
pos += 1;
if (pos == BUFFER_SIZE){
bufferFlag = true;
pos = 0;
}
EICRA &= ~(1 << ISC01);
}
if (sendFlag && bufferFlag)
{
for (unsigned int i=0; i<BUFFER_SIZE; i++)
{
byte highByte = bufferM[i] & 0xFF;
byte lowByte = (bufferM[i] >> 8) & 0xFF;
blue.write(highByte);
blue.write(lowByte);
Serial.println(bufferM[i]);
}
bufferFlag = false;
}
}
void Muestreo() {
EICRA |= (1 << ISC01);
}