Example code 06

Dependencies:   mbed

Fork of STMNucleoF401RE_ExampleCode_06_VariableR by 20161020-Corso Rapid Prototyping with STM32Nucleo

Il circuito

/media/uploads/perlatecnica/circuitopotenziometro.jpg

Committer:
nicolaesposito
Date:
Wed Mar 01 14:04:14 2017 +0000
Revision:
2:67c48dcc85f0
Parent:
1:25052aedb239
VERSIONE SEQUENZA LED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
perlatecnica 0:4a795cf05594 1 /****************************************************
perlatecnica 0:4a795cf05594 2 * FAST PROTOTYPING WITH NUCLEO *
perlatecnica 0:4a795cf05594 3 * Example Code 06: Variable resistor *
perlatecnica 0:4a795cf05594 4 * Author: Mauro D'Angelo *
STmdangelo 1:25052aedb239 5 * Organization: STMicroelectronics *
perlatecnica 0:4a795cf05594 6 *****************************************************/
perlatecnica 0:4a795cf05594 7
perlatecnica 0:4a795cf05594 8 #include "mbed.h"
perlatecnica 0:4a795cf05594 9
perlatecnica 0:4a795cf05594 10 // Instanzia un oggetto di tipo AnalogIn che chiamo analog_value, e lo assegna al pin A0
perlatecnica 0:4a795cf05594 11 AnalogIn analog_value(A0);
nicolaesposito 2:67c48dcc85f0 12 BusOut Bar(PC_8,PC_6,PC_5,PA_12,PA_11,PB_12,PB_2,PB_1,PB_15,PB_14);
perlatecnica 0:4a795cf05594 13 DigitalOut led(LED1);
perlatecnica 0:4a795cf05594 14
perlatecnica 0:4a795cf05594 15 int main() {
perlatecnica 0:4a795cf05594 16 float meas;
perlatecnica 0:4a795cf05594 17
perlatecnica 0:4a795cf05594 18 while(1) {
perlatecnica 0:4a795cf05594 19 meas = analog_value.read(); // It reads the analog input value (value from 0.0 to 1.0)
nicolaesposito 2:67c48dcc85f0 20
nicolaesposito 2:67c48dcc85f0 21 // int i=int(10*meas);
nicolaesposito 2:67c48dcc85f0 22 //
perlatecnica 0:4a795cf05594 23 meas = meas * 3300; // Change the value to be in the 0 to 3300 range
nicolaesposito 2:67c48dcc85f0 24 float i=(meas/330);
nicolaesposito 2:67c48dcc85f0 25 printf("intero = %.2f \r\n", i);
perlatecnica 0:4a795cf05594 26 printf("measure = %.2f mV\r\n", meas);
nicolaesposito 2:67c48dcc85f0 27
nicolaesposito 2:67c48dcc85f0 28 // printf("calcolo i = %.2f mV\r\n", i);
nicolaesposito 2:67c48dcc85f0 29 int j=int(i);
nicolaesposito 2:67c48dcc85f0 30 printf("valore j = %d\n", j);
nicolaesposito 2:67c48dcc85f0 31 Bar =1<<j;
nicolaesposito 2:67c48dcc85f0 32 if (meas < 2500) { // If the value is greater than 2V then switch the LED on
nicolaesposito 2:67c48dcc85f0 33 led = 1;
perlatecnica 0:4a795cf05594 34 }
perlatecnica 0:4a795cf05594 35 else {
perlatecnica 0:4a795cf05594 36 led = 0;
perlatecnica 0:4a795cf05594 37 }
nicolaesposito 2:67c48dcc85f0 38 wait(.1); // 200 ms
perlatecnica 0:4a795cf05594 39 }
perlatecnica 0:4a795cf05594 40 }