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.
main.cpp
- Committer:
- nekoyyy
- Date:
- 2014-01-23
- Revision:
- 8:3eb58ae94a93
- Parent:
- 7:1947b554f8e3
- Child:
- 9:215d94939bc9
File content as of revision 8:3eb58ae94a93:
#include "mbed.h"
#include "rtos.h"
Serial pc(USBTX, USBRX);
PwmOut Dou1(p21);
PwmOut Asi1(p23);
PwmOut Dou2(p22);
PwmOut Asi2(p24);
char c;
int zen1=0;
int go1=0;
int zen2=0;
int go2=0;
int dou1=0;
void HANTEI(void const *argument) {
while(true){
if(pc.readable()==1){
c=pc.getc();
switch(c){
case'g':
zen1=1;
c=0;
pc.printf("go\n");
break;
case'n':
zen1=0;
go1=0;
c=0;
pc.printf("stop\n");
break;
case'z':
go1=1;
c=0;
pc.printf("zen\n");
break;
case'c':
zen2=1;
c=0;
pc.printf("go\n");
break;
case'p':
zen2=0;
go2=0;
c=0;
pc.printf("stop\n");
break;
case'x':
go2=1;
c=0;
pc.printf("zen\n");
break;
case'd':
dou1=1;
c=0;
pc.printf("dou\n");
break;
}
}
}
}
void ZENGO1(void const *argument) {
Asi1.period(0.00001);
while(true){
if(go1==1){
Asi1.pulsewidth(0.00000f);
}
else if(zen1==1){
Asi1.pulsewidth(0.00001f);
}
else{
Asi1.pulsewidth(0.000005f);
}
}
}
void ZENGO2(void const *argument) {
Asi2.period(0.00001);
while(true){
if(zen2==1){
Asi2.pulsewidth(0.000006f);
}
else if(go2==1){
Asi2.pulsewidth(0.000004f);
}
else{
Asi2.pulsewidth(0.000005f);
}
}
}
void DOU1(void const *argument) {
Dou1.period(0.00001);
int i=1;
int d=1;
while(true){
if(dou1==1){
switch(d){
case 1:
Dou1.pulsewidth(0.000004f);
i=i++;
wait(0.02);
if(i>50)d=2;
break;
case 2:
Dou1.pulsewidth(0.000006f);
i=i--;
wait(0.02);
if(i>2){
d=1;
dou1=0;
}
break;
}
}
}
}
int main() {
Thread t1(HANTEI);
Thread t2(ZENGO1);
Thread t3(ZENGO2);
Thread t4(DOU1);
pc.printf("start\n");
while(1);
}