![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proyecto que lee un buffer de la entrada y lo manda por el serial
main.cpp@1:1895d2877fef, 2019-10-15 (annotated)
- Committer:
- jvicente
- Date:
- Tue Oct 15 15:09:15 2019 +0000
- Revision:
- 1:1895d2877fef
- Parent:
- 0:d8bdd80b93fe
cambio delay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jvicente | 0:d8bdd80b93fe | 1 | #include "mbed.h" |
jvicente | 0:d8bdd80b93fe | 2 | #define bufferLength 256 |
jvicente | 0:d8bdd80b93fe | 3 | |
jvicente | 1:1895d2877fef | 4 | Serial pc(USBTX, USBRX,115200); // tx, rx |
jvicente | 1:1895d2877fef | 5 | |
jvicente | 0:d8bdd80b93fe | 6 | AnalogIn analog_value(A0); |
jvicente | 0:d8bdd80b93fe | 7 | Ticker tMuestrea; |
jvicente | 0:d8bdd80b93fe | 8 | int flag=0; |
jvicente | 0:d8bdd80b93fe | 9 | int contador=0; |
jvicente | 0:d8bdd80b93fe | 10 | uint16_t buffer[bufferLength]; |
jvicente | 0:d8bdd80b93fe | 11 | void muestrea(); |
jvicente | 0:d8bdd80b93fe | 12 | |
jvicente | 0:d8bdd80b93fe | 13 | int main() |
jvicente | 0:d8bdd80b93fe | 14 | { |
jvicente | 1:1895d2877fef | 15 | |
jvicente | 0:d8bdd80b93fe | 16 | tMuestrea.attach(&muestrea, 0.001); |
jvicente | 0:d8bdd80b93fe | 17 | printf("\nAnalogIn example\n"); |
jvicente | 0:d8bdd80b93fe | 18 | while(1) { |
jvicente | 0:d8bdd80b93fe | 19 | if (flag) { |
jvicente | 0:d8bdd80b93fe | 20 | for (int n=0; n<bufferLength; n++) { |
jvicente | 1:1895d2877fef | 21 | pc.printf("%d\n",buffer[n]); |
jvicente | 0:d8bdd80b93fe | 22 | } |
jvicente | 0:d8bdd80b93fe | 23 | flag=0; |
jvicente | 0:d8bdd80b93fe | 24 | } |
jvicente | 1:1895d2877fef | 25 | wait_us(1); |
jvicente | 0:d8bdd80b93fe | 26 | } |
jvicente | 0:d8bdd80b93fe | 27 | } |
jvicente | 0:d8bdd80b93fe | 28 | |
jvicente | 0:d8bdd80b93fe | 29 | void muestrea() |
jvicente | 0:d8bdd80b93fe | 30 | { |
jvicente | 0:d8bdd80b93fe | 31 | if(flag==0) { |
jvicente | 0:d8bdd80b93fe | 32 | buffer[contador]=analog_value.read_u16(); |
jvicente | 0:d8bdd80b93fe | 33 | contador++; |
jvicente | 0:d8bdd80b93fe | 34 | if(contador==256) { |
jvicente | 0:d8bdd80b93fe | 35 | flag=1; |
jvicente | 0:d8bdd80b93fe | 36 | contador=0; |
jvicente | 0:d8bdd80b93fe | 37 | } |
jvicente | 0:d8bdd80b93fe | 38 | } |
jvicente | 0:d8bdd80b93fe | 39 | } |