Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, this is my project video. https://www.youtube.com/watch?v=nOw5-IvPDgk .Our microprocessor teacher gave us a project assignment that we can do with NUCLEO-F401RE. Most projects made by

Hello, this is my project video. https://www.youtube.com/watch?v=nOw5-IvPDgk .Our microprocessor teacher gave us a project assignment that we can do with "NUCLEO-F401RE". Most projects made by converting projects made with Arduino become projects. I also want to make smart staircase lighting. I need code help for this. I asked for code help from here. This project has been realized with Arduino. https://github.com/ckaplan831/AKILI-MERD-VEN-KOD-VE-BA-LANTI-SEMASI- . I asked this question as I was having trouble translating it to the Cube IDE code. Please I need the Cube IDE code. The Arduino code of my project is as follows.

const int pir_pin_up = 12; const int pir_pin_down = 13; int pir_up_deger; int pir_down_deger;

int merdiven_led_up[11] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, A5,}; // string int merdiven_led_down[11] = {A5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,}; // reverse string

int y = 400; // light on interval int b = 5000; // light off interval after full lighting int s = 800; // light off interval

void setup() { pinMode(pir_pin_up, INPUT); // stteki pir sensor pini giri tanmland pinMode(pir_pin_down, INPUT); // alttaki pir sensor pini giri tanmland

for (int i = 0; i < 12; i++) { pinMode(merdiven_led_up[i], OUTPUT); //dizideki tm ledler k olarak ayarland pinMode(merdiven_led_down[i], OUTPUT); //dizideki tm ledler k olarak ayarland }

}

void loop() { pir_up_deger = digitalRead(pir_pin_up); //st pir pin deeri pir_up_deger e atand pir_down_deger = digitalRead(pir_pin_down); //alt pir pin deeri pir_down_deger e atand

if (pir_up_deger == HIGH) // eer st pir den sinyal gelirse { stairs_from_up(); // bu fonksiyonu altr }

if (pir_down_deger == HIGH) // eer alt pir den sinyal gelirse { stairs_from_down(); // bu fonksiyonu altr }

else // bu artlardan hibiri olmazsa { kapat(); // bu fonksiyonu altr }

} ///////// fonksiyon tanmlar \\\\\\\\\\

void stairs_from_up() // stten merdivene ayak basldnda alacak fonksiyon { for (int i = 0; i < 12; i++) { digitalWrite(merdiven_led_up[i], HIGH); delay(y); } delay(b); for (int i = 0; i < 12; i++) { digitalWrite(merdiven_led_up[i], LOW); delay(s); }

}

void stairs_from_down() // alltan merdivene ayak basldnda alacak fonksiyon { for (int i = 0; i < 12; i++) { digitalWrite(merdiven_led_down[i], HIGH); delay(y); } delay(b); for (int i = 0; i < 12; i++) { digitalWrite(merdiven_led_down[i], LOW); delay(s); }

}

void kapat() // if komut artlarnn olumad durumda alacak fonksiyon { for (int i = 0; i < 12; i++) { digitalWrite(merdiven_led_up[i], LOW); digitalWrite(merdiven_led_down[i], LOW);

} }

Here are the Cube IDE codes that I know for this project.

#include

#include "stm32f4xx_hal.h"

#define LED_PIN GPIO_PIN_5

#define LED_PORT GPIOC

int main(void)

{

// Initialize LED

LED_PORT->MODER |= (1 << (LED_PIN * 2));

while (1)

{

// Turn LED on

LED_PORT->ODR |= LED_PIN;

// Delay for 1 second

HAL_Delay(1000);

// Turn LED off

LED_PORT->ODR &= ~LED_PIN;

// Delay for 1 second

HAL_Delay(1000);

}

}

This code will blink an LED connected to pin 5 of the GPIOC port on the NUCLEO-F401RE microcontroller. To use this code, you will need to include the necessary libraries (such as "stm32f4xx_hal.h") and configure the LED_PIN and LED_PORT constants to match your hardware setup.

To implement more advanced functionality for your smart staircase lighting system, you will need to add additional code to handle things like sensor input, communication with other devices, and so on. However, this basic example should give you an idea of how to control an LED using the NUCLEO-F401RE microcontroller and the Cube IDE.

and

#include "mbed.h"

// Define the pins for the infrared distance sensor

#define TRIGGER_PIN PB_10

#define ECHO_PIN PB_4

// Define the pin for the LED strip

#define LED_STRIP_PIN PB_3

// Create an instance of the DigitalOut class for the LED strip

DigitalOut ledStrip(LED_STRIP_PIN);

// Create an instance of the DigitalOut class for the trigger pin

DigitalOut trigger(TRIGGER_PIN);

// Create an instance of the DigitalIn class for the echo pin

DigitalIn echo(ECHO_PIN);

// Create a timer to measure the duration of the pulse

Timer pulseTimer;

int main() {

// Set the trigger pin to low initially

trigger = 0;

// Set the LED strip to off initially

ledStrip = 0;

while(1) {

// Send a pulse to the infrared distance sensor by setting the trigger pin to high for 10 microseconds

trigger = 1;

wait_us(10);

trigger = 0;

// Start the timer

pulseTimer.reset();

pulseTimer.start();

// Wait for the echo pin to go high, indicating that the pulse has been received

while(echo == 0);

// Stop the timer

pulseTimer.stop();

// Calculate the distance based on the duration of the pulse

float distance = pulseTimer.read() * 17150;

// If the distance is less than 50 cm, turn on the LED strip

if(distance < 50) {

ledStrip = 1;

} else {

ledStrip = 0;

}

// Wait for 500 milliseconds before sending the next pulse

wait(0.5);

}

}

I don't know how to adapt all my variables to the cube ide program and I need your help.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions

Question

Identify and describe the two major symptoms of bipolar disorder.

Answered: 1 week ago

Question

Design a job advertisement.

Answered: 1 week ago