In the past week I have been doing a lot of programming for the sensors It has been a bit of a learning experience working with the Nucleo-L476RG especially since I have been using the Arduino IDE The main part to remember is to assign the pins in your coding with the code"pinMap So far there has been no issue programming the Nucleo with the Arduino IDE everything is working perfectly
Attached is the code I have done so far:
#include <f401reMap.h> #define THRESHOLD 2 const int sigPin = pinMap(7); // Tilt sensor const int ledPin = pinMap(8); // the number of the LED pin int noisesense = pinMap(1); // Sound sensor int touchO = pinMap(2); int touchI = pinMap(3); int val = 0; int valB = 0; int capI; boolean sigState = 0; // variable for reading the tilt switch status void setup() { Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the tilt sensor pin as an input: pinMode(sigPin, INPUT); // initialize the sound sensor pin as an input: pinMode(noisesense, INPUT); } void loop() { // Capacitance sensor start capI = 0; // clear out capacitance measure at each loop digitalWrite(touchO, HIGH); int valB = digitalRead(touchI); // read the input to be checked while (valB != HIGH){ capI++; valB = digitalRead(touchI); // re-read the input to be checked } delay(1); digitalWrite(touchO, LOW); Serial.println(capI, DEC); // print out interval if (capI > THRESHOLD) digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); // Capacitive sensor end //////////////////////////////// // read tilt switch value: sigState = digitalRead(sigPin); // read sound sensor val = digitalRead(noisesense);// digital interface will be assigned a value of pin 1 to read val // tilt action if (sigState == HIGH) { // turn LED on digitalWrite(ledPin, LOW); } else { // turn LED off: digitalWrite(ledPin, HIGH); } // Sound action if (val == HIGH) { // turn LED on digitalWrite(ledPin, LOW); } else { // turn LED off: digitalWrite(ledPin, HIGH); } }
The code above controls the sound, tilt and capacitive touch sensors. I still require to code for the heart, vibration and temperature sensors as well as the speaker. Once I am completed the coding for the remaining sensors I will be ready for live testing in the vehicle. So far this challenge has been a lot of fun and a great learning experience. I am very confident that I will be finished by the completion date of this challenge.
Thank you for reading and following my blogs
Dale W
Top Comments