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.
Fork of moter_titech by
main.cpp
- Committer:
- senna0116
- Date:
- 2014-01-24
- Revision:
- 11:5cd36eedffb3
- Parent:
- 10:808032cf71b0
File content as of revision 11:5cd36eedffb3:
#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;
int dou2=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\r\n");
break;
case'n':
zen1=0;
go1=0;
c=0;
pc.printf("stop\r\n");
break;
case'z':
go1=1;
c=0;
pc.printf("zen\r\n");
break;
case'c':
zen2=1;
c=0;
pc.printf("go\r\n");
break;
case'p':
zen2=0;
go2=0;
c=0;
pc.printf("stop\r\n");
break;
case'x':
go2=1;
c=0;
pc.printf("zen\r\n");
break;
case'd':
dou1=1;
c=0;
pc.printf("dou\r\n");
break;
case'q':
dou2=1;
c=0;
pc.printf("dou_2gouki\r\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.00001f);
Dou1.pulsewidth(0.000005f);
int i=1;
int d=1;
while(true){
if(dou1==1){
switch(d){
case 1:
Dou1.pulsewidth(0.000006f);
i=i++;
wait(0.02);
if(i>50)d=2;
break;
case 2:
Dou1.pulsewidth(0.000005f);
i=i--;
wait(0.02);
if(i<2){
d=1;
dou1=0;
}
break;
}
}
}
}
void DOU2(void const *argument) {
Dou2.period(0.00001);
Dou2.pulsewidth(0.000005f);
int j=1;
int q=1;
while(true){
if(dou2==1){
switch(q){
case 1:
Dou2.pulsewidth(0.000006f);
j=j++;
wait(0.02);
if(j>50)q=2;
break;
case 2:
Dou2.pulsewidth(0.000005f);
j=j--;
wait(0.02);
if(j<2){
q=1;
dou2=0;
}
break;
}
}
}
}
int main() {
Thread t1(HANTEI);
Thread t2(ZENGO1);
Thread t3(ZENGO2);
Thread t4(DOU1);
// Thread t5(DOU2);
pc.printf("start\r\n");
while(1);
}
