Receives a measured height of a ping-pong ball from a PC, and uses it to control the PWM of a fan to keep the height as set with the keypad. Information is shown on the LCD
Fork of mbed-os-example-mbed5-blinky by
Revision 39:e4f5710b2f31, committed 2017-06-28
- Comitter:
- gunarthon
- Date:
- Wed Jun 28 16:36:16 2017 +0000
- Parent:
- 38:b760c09b311c
- Child:
- 40:19d51f6e6800
- Commit message:
- added serial
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jun 15 23:19:38 2017 +0000
+++ b/main.cpp Wed Jun 28 16:36:16 2017 +0000
@@ -2,6 +2,7 @@
#include "Queue.h"
#include "TextLCD.h"
#include "pid.h"
+#include <Serial.h>
//definitions
typedef struct {
@@ -9,6 +10,7 @@
} message_t;
const int heightResolution = 1024;
+const int BAUDRATE = 115200;
const double setPoint = 0.5;
const double Kp = 1;
const double Ki = 0.2;
@@ -34,6 +36,8 @@
MemoryPool<message_t, 16> mpool;
Queue<message_t,16> messageQueue;
+void SerialCallback(int);
+
//=============================Thread Methodes==================================
void BlueMethode(void)
@@ -79,16 +83,30 @@
void CommunicationMethode(void)
{
- uint32_t input = 0;
+ Serial serial(USBTX, USBRX);
+ serial.baud(BAUDRATE);
+ serial.format(8, SerialBase::None, 1);
+ uint16_t input = 0;
+
+ //event_callback_t functionpointer;
+ //functionpointer.attach(&SerialCallback);
+
while(true)
{
- input = input>=1000 ? 0 : input+1;
+ //serial.read(&input, 1, functionpointer);
+ input = serial.getc()+(serial.getc()<<8);
+ //lcd.cls();
+ //lcd.printf("%d", int(input));
message_t *message = mpool.alloc();
message->input = input;
messageQueue.put(message);
- Thread::wait(100);
}
}
+/*
+void SerialCallback(int)
+{
+ //ut =
+}*/
//------------------------------------------------------------------------------
//human-machine interface
