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.
Dependents: NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo
ikarashiSV.cpp
- Committer:
- ikarashikota
- Date:
- 2021-10-15
- Revision:
- 1:696f7c0ab1bd
- Parent:
- 0:2b253298d427
- Child:
- 3:1fc2008f3a07
File content as of revision 1:696f7c0ab1bd:
#include "ikarashiSV.h"
ikarashiSV::ikarashiSV(PinName pin_a,PinName pin_b,PinName pin_c,PinName pin_d):
port_a(pin_a), port_b(pin_b), port_c(pin_c), port_d(pin_d)
{
state = 0;
solenoid_status = 0;
}
void ikarashiSV::add_state()
{
state++;
}
void ikarashiSV::solenoid(int _state)
{
switch(_state) {
case 1:
//下だけ上がる
port_a = 1;
port_b = 0;
solenoid_status = 1;
break;
case 2:
//投げる
port_c = 1;
port_d = 0;
solenoid_status = 2;
break;
case 0:
//戻る
port_c = 0;
port_d = 1;
wait(0.3);
port_a = 0;
port_b = 1;
solenoid_status = 0;
break;
}
}
void ikarashiSV::solenoid_show()
{
switch(solenoid_status) {
case 1:
printf("1:push\n\r");
break;
case 2:
printf("\t2:push\n\r");
break;
case 0:
printf("1:pull 2:pull\n\r");
break;
}
}
int ikarashiSV::state_show()
{
return state;
}
/* サンプルコード
#include "mbed.h"
#include "ikarashiSV.h"
Serial pc(USBTX, USBRX,115200);
ikarashiSV slv(PC_7,PB_10,PB_4,PB_5);
//ボタンを押したときor離したときを読み取る定義の仕方
InterruptIn button(USER_BUTTON);
void add()
{
slv.add_state();
}
int main()
{
int val;
while(1) {
button.fall(&add);
val = slv.state_show();
pc.printf("\t\tstate : %d",val);
if(val >= 1) {
slv.solenoid(val%3);
}
slv.solenoid_show();
}
}
*/