Yeongsoo Kim / Mbed 2 deprecated Mecha_Servo_n_Distance_sensor

Dependencies:   mbed

Committer:
yeongsookim
Date:
Mon Nov 11 00:06:25 2019 +0000
Revision:
0:b638163ed537
19.11.11 mechatronics lecture distrubution; PSD (distance sensor) and Servo motor control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yeongsookim 0:b638163ed537 1 #include "Plotting.h"
yeongsookim 0:b638163ed537 2
yeongsookim 0:b638163ed537 3 Plotting::Plotting()
yeongsookim 0:b638163ed537 4 {
yeongsookim 0:b638163ed537 5 for(int i=0; i<32; i++) {
yeongsookim 0:b638163ed537 6 datas[i]=0;
yeongsookim 0:b638163ed537 7 }
yeongsookim 0:b638163ed537 8 dataCount=0;
yeongsookim 0:b638163ed537 9 }
yeongsookim 0:b638163ed537 10
yeongsookim 0:b638163ed537 11 void Plotting::reset()
yeongsookim 0:b638163ed537 12 {
yeongsookim 0:b638163ed537 13 for(int i=0; i<32; i++) {
yeongsookim 0:b638163ed537 14 datas[i]=0;
yeongsookim 0:b638163ed537 15 }
yeongsookim 0:b638163ed537 16 dataCount=0;
yeongsookim 0:b638163ed537 17 }
yeongsookim 0:b638163ed537 18
yeongsookim 0:b638163ed537 19 void Plotting::put(float data, int index)
yeongsookim 0:b638163ed537 20 {
yeongsookim 0:b638163ed537 21 datas[index]=data;
yeongsookim 0:b638163ed537 22 dataCount++;
yeongsookim 0:b638163ed537 23 }
yeongsookim 0:b638163ed537 24
yeongsookim 0:b638163ed537 25 void Plotting::put(int data, int index)
yeongsookim 0:b638163ed537 26 {
yeongsookim 0:b638163ed537 27 datas[index]=(float)data;
yeongsookim 0:b638163ed537 28 dataCount++;
yeongsookim 0:b638163ed537 29 }
yeongsookim 0:b638163ed537 30
yeongsookim 0:b638163ed537 31 void Plotting::put(unsigned int data, int index)
yeongsookim 0:b638163ed537 32 {
yeongsookim 0:b638163ed537 33 datas[index]=(float)data;
yeongsookim 0:b638163ed537 34 dataCount++;
yeongsookim 0:b638163ed537 35 }
yeongsookim 0:b638163ed537 36
yeongsookim 0:b638163ed537 37 void Plotting::send(Serial *port)
yeongsookim 0:b638163ed537 38 {
yeongsookim 0:b638163ed537 39 port->putc(0xAA);
yeongsookim 0:b638163ed537 40 port->putc(0xBB);
yeongsookim 0:b638163ed537 41 port->putc(0xCC);
yeongsookim 0:b638163ed537 42 port->putc((char)(dataCount*4));
yeongsookim 0:b638163ed537 43 for(int i=0; i<dataCount; i++) {
yeongsookim 0:b638163ed537 44 char *bytePtr = (char *)&(datas[i]);
yeongsookim 0:b638163ed537 45 port->putc(*bytePtr); // reverse the order of these lines if you have endian issues
yeongsookim 0:b638163ed537 46 port->putc(*(bytePtr+1));
yeongsookim 0:b638163ed537 47 port->putc(*(bytePtr+2));
yeongsookim 0:b638163ed537 48 port->putc(*(bytePtr+3));
yeongsookim 0:b638163ed537 49 }
yeongsookim 0:b638163ed537 50 }