Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:1ff9e3618717, committed 2017-03-19
- Comitter:
- yyue
- Date:
- Sun Mar 19 22:27:07 2017 +0000
- Commit message:
- project
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,158 @@
+#include "mbed.h"
+#include "Motor.h"
+#include "Light.h"
+#include "Button.h"
+#include "Switch.h"
+
+#include "Led.h"
+
+Timer timer;
+Led myled(PD_15);
+Led myled1(PD_12);
+Led myled2(PD_13);
+Led myled3(PD_14);
+
+Motor step1(PE_9);
+Motor step2(PE_11);
+Motor step3(PE_13);
+Motor step4(PE_14);
+
+Motor step5(PC_6);
+Motor step6(PC_7);
+Motor step7(PC_8);
+Motor step8(PC_9);
+
+Light light(PA_2);
+
+Switch switch1(PA_3);
+
+Switch switch2(PA_4);
+
+
+Button button(PA_0);
+
+int main()
+{
+ float delay = 0.01f;
+ while(1) {
+ //while(button.isPressed()) {
+ step1.switchOff();
+ step2.switchOff();
+ step3.switchOff();
+ step4.switchOff();
+
+ step5.switchOff();
+ step6.switchOff();
+ step7.switchOff();
+ step8.switchOff();
+
+
+ int Open = light.open();
+ //int Close = light.close();
+ int i=0;
+
+ //float time1 = timer.read();
+ //float time2;
+ //float time;
+
+ while(Open) {
+ myled.flash(0.1);
+
+ //if (button.isPressed()){
+ // myled.switchOff();
+ // }
+ //int led = rand() % 4;
+ step1.switchOn();
+ step5.switchOn();
+ // myled.flash(0.1);
+ wait(delay);
+
+ step1.switchOff();
+ step5.switchOff();
+
+ step2.switchOn();
+ step6.switchOn();
+ //myled1.flash(0.1);
+ wait(delay);
+
+ step2.switchOff();
+ step6.switchOff();
+
+ step3.switchOn();
+ step7.switchOn();
+ //myled2.flash(0.1);
+ wait(delay);
+
+ step3.switchOff();
+ step7.switchOff();
+
+ step4.switchOn();
+ step8.switchOn();
+ //myled3.flash(0.1);
+ wait(delay);
+ step4.switchOff();
+ //time2=timer.read();
+ //time= time2-time1;
+
+ //i++;
+ if (switch1.stopmotor() || i >= 300) {
+
+ Open = 0;
+ }
+
+ }
+
+ int Close = light.close();
+
+
+
+ while(Close) {
+ step4.switchOn();
+ step8.switchOn();
+ //myled.flash(0.1);
+ wait(delay);
+
+ step4.switchOff();
+ step8.switchOff();
+
+ step3.switchOn();
+ step7.switchOn();
+ //myled1.flash(0.1);
+ wait(delay);
+
+ step3.switchOff();
+ step7.switchOff();
+
+ step2.switchOn();
+ step6.switchOn();
+ //myled2.flash(0.1);
+ wait(delay);
+
+ step2.switchOff();
+ step6.switchOff();
+
+ step1.switchOn();
+ step5.switchOn();
+ //myled3.flash(0.1);
+ wait(delay);
+ step1.switchOff();
+
+ // time2=timer.read();
+ // time= time2-time1;
+ // i++;
+ if (switch2.stopmotor() || i >= 300) {
+
+ Close = 0;
+ }
+
+
+
+
+ }
+
+
+
+
+
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Mar 19 22:27:07 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Button.cpp Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,31 @@
+#include "Button.h"
+Button::Button(PinName pinName) :
+ pin(pinName)
+{
+}
+
+bool Button::isPressed()
+{
+ int pinValue = pin.read();
+ if (pinValue == 1) {
+ return true;
+ } else {
+ return false;
+ }
+}
+float Button::getPulse()
+{
+ int end;
+ while(this->isPressed() == false) {
+ }
+
+ Timer timer;
+ timer.start();
+
+ while(this->isPressed() == true) {
+ wait(0.01);
+ }
+
+ end=timer.read();
+ timer.stop();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Button.h Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,13 @@
+#ifndef _BUTTON_H_
+#define _BUTTON_H_
+#include "mbed.h"
+class Button
+{
+private:
+ DigitalOut pin;
+public:
+ Button(PinName pinName);
+ bool isPressed();
+ float getPulse();
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Led.cpp Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,17 @@
+#include "Led.h"
+Led::Led(PinName pinName) :
+pin(pinName)
+{
+}
+
+void Led::switchOn(){
+ this->pin = 1;
+}
+void Led::switchOff(){
+ this->pin = 0;
+}
+void Led::flash(float time) {
+ this->pin = 1;
+ wait(time);
+ this->pin = 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Led.h Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,15 @@
+#ifndef _LED_H_
+#define _LED_H_
+#include "mbed.h"
+class Led
+{
+public:
+ Led(PinName pinName);
+ void switchOn();
+ void switchOff();
+ void flash(float time);
+private:
+ DigitalOut pin;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Light.cpp Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,38 @@
+#include "Light.h"
+Light::Light(PinName pinName) :
+ pin(pinName)
+{
+}
+
+bool Light::open()
+{
+ int pinValue1 = pin.read();
+ wait(1.0f);
+ int pinValue2 = pin.read();
+ if (pinValue1 == 0) {
+ if (pinValue1 == pinValue2) {
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
+}
+
+bool Light::close()
+{
+ int pinValue1 = pin.read();
+ wait(1.0f);
+ int pinValue2 = pin.read();
+
+ if (pinValue1 == 1) {
+ if (pinValue1 == pinValue2) {
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return false;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Light.h Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,18 @@
+#ifndef _LIGHT_H_
+#define _LIIGHT_H_
+#include "mbed.h"
+
+class Light
+{
+ public:
+ Light(PinName pinName);
+ bool open();
+ bool close();
+
+ private:
+ DigitalIn pin;
+
+
+
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Motor.cpp Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,17 @@
+#include "Motor.h"
+Motor::Motor(PinName pinName) :
+pin(pinName)
+{
+}
+
+void Motor::switchOn(){
+ this->pin = 1;
+}
+void Motor::switchOff(){
+ this->pin = 0;
+}
+void Motor::flash(float time) {
+ this->pin = 1;
+ wait(time);
+ this->pin = 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Motor.h Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,15 @@
+#ifndef _MOTOR_H_
+#define _MOTOR_H_
+#include "mbed.h"
+class Motor
+{
+public:
+ Motor(PinName pinName);
+ void switchOn();
+ void switchOff();
+ void flash(float time);
+private:
+ DigitalOut pin;
+};
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Switch.cpp Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,19 @@
+#include "Switch.h"
+Switch::Switch(PinName pinName) :
+ pin(pinName)
+{
+}
+
+bool Switch::stopmotor()
+{
+ int pinValue = pin.read();
+
+ if (pinValue == 0) {
+
+ return true;
+
+ } else {
+ return false;
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefilter/Switch.h Sun Mar 19 22:27:07 2017 +0000
@@ -0,0 +1,18 @@
+#ifndef _SWITCH_H_
+#define _SWITCH_H_
+#include "mbed.h"
+
+class Switch
+{
+ public:
+ Switch(PinName pinName);
+ bool stopmotor();
+ //bool normalclose();
+
+ private:
+ DigitalIn pin;
+
+
+
+};
+#endif
\ No newline at end of file