Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone change the following c++ code to Python please. It is a code I am using for the SEN0192 microwave sensor using an arduino

Can someone change the following c++ code to Python please. It is a code I am using for the SEN0192 microwave sensor using an arduino uno but now I have to use it with a raspberry pi but don't have enough time to learn phython. Thank you.

#include //Timer interrupt function library int pbIn = 0; // Define interrupt 0 that is digital pin 2 int ledOut = 13; // Define the indicator LED pin digital pin 13 int number=0; //Interrupt times volatile int state = LOW; // Defines the indicator LED state, the default is not bright void setup() { Serial.begin(9600); pinMode(ledOut, OUTPUT);// attachInterrupt(pbIn, stateChange, FALLING); // Set the interrupt function, interrupt pin is digital pin D2, interrupt service function is stateChange (), when the D2 power change from high to low , the trigger interrupt. MsTimer2::set(1000, Handle); // Set the timer interrupt function, running once Handle() function per 1000ms MsTimer2::start();//Start timer interrupt function

} void loop() { Serial.println(number); // Printing the number of times of interruption, which is convenient for debugging. delay(1); if(state == HIGH) //When a moving object is detected, the ledout is automatically closed after the light 2S, the next trigger can be carried out, and No need to reset. Convenient debugging. { delay(2000); state = LOW; digitalWrite(ledOut, state); //turn off led }

} void stateChange() //Interrupt service function { number++; //Interrupted once, the number +1

}

void Handle() //Timer service function { if(number>1) //If in the set of the interrupt time the number more than 1 times, then means have detect moving objects,This value can be adjusted according to the actual situation, which is equivalent to adjust the threshold of detection speed of moving objects. { state = HIGH; digitalWrite(ledOut, state); //light led number=0; //Cleare the number, so that it does not affect the next trigger } else number=0; //If in the setting of the interrupt time, the number of the interrupt is not reached the threshold value, it is not detected the moving objects, Cleare the number. }

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

What pH range does noncorrosive waste display?

Answered: 1 week ago

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago