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.
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
Diff: main.cpp
- Revision:
- 2:aee655d11b6d
- Parent:
- 1:b862262a9d14
- Child:
- 3:710f993d5848
--- a/main.cpp Wed Sep 04 15:30:13 2019 +0000
+++ b/main.cpp Mon Oct 07 07:39:29 2019 +0000
@@ -4,20 +4,53 @@
#include "MODSERIAL.h"
//#include "BiQuad.h"
//#include "FastPWM.h"
+#include <math.h>
-DigitalOut led(LED_RED);
+Serial pc(USBTX, USBRX);
+Ticker myControllerTicker;
+AnalogIn potMeter(A0);
+PwmOut fan(D5); // kan ook D6 zijn
+DigitalOut fan_dir(D4);
+InterruptIn button1(D2);
+
+void direction(void)
+ {
+ fan_dir=!fan_dir;
+
+ pc.printf("hello");
+ }
+
+
+
-MODSERIAL pc(USBTX, USBRX);
+// Feed forward fan speed controller
+// Suppose an AnalogIn ’potMeter’ and PWMOut ’fan’
+void fanController( )
+{
+// Determine reference (desired) fan speed
+double y_des = potMeter.read();
+// Controller (calculate motor torque/pwm)
+if( y_des > 1 ) y_des = 1; // y_des must be <= 1
+if( y_des < 0 ) y_des = 0; // y_des must be >= 0
+double u = pow(y_des, 2.0); // Inverse relation between input and output
+// Send to motor
+fan.write( u );
+pc.printf("u: %.2f\n\r",u);
+}
+
+
int main()
{
- pc.baud(115200);
- pc.printf("\r\nStarting...\r\n\r\n");
-
- while (true) {
-
- led = !led;
-
- wait_ms(500);
- }
+myControllerTicker.attach( fanController, 0.1 ); // Every second
+
+button1.mode(PullUp);
+button1.rise(direction);
+
+while( true ) { /* do nothing */ }
+return 0;
}
+
+
+
+