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.
Dependencies: mbed
Fork of circle_war_ver_A_NUCLEO_ by
Diff: spi_nucleo.h
- Revision:
- 2:bed6b204e64c
- Parent:
- 1:86d25c1c4bd5
- Child:
- 3:6ab4e8e3aa02
- Child:
- 5:df89be97e11a
--- a/spi_nucleo.h Fri Mar 25 03:08:41 2016 +0000 +++ b/spi_nucleo.h Fri Mar 25 04:21:52 2016 +0000 @@ -1,23 +1,23 @@ #ifndef SPI_NUCLEO_H #define SPI_NUCLEO_H +#include "pin_file.h" +#include <string.h> + //SPI mbed -SPI from_mbed(PA_5, PA_6, PA_7); -DigitalIn (PA_4); -int FM; bool RR; bool LR; char speed_X; char speed_Y; + //SPI NUCLEO - - - -SPI from_gyro(PB_13, PB_14, PB_15); -DigitalIn (PB_12); -int G; void spi_mbed(); void spi_nucleo(); - +void getGyro(); +void spiInit(); +typedef unsigned short u16; +long int angle; +double now_angle; +Serial pc(USBTX,USBRX); #endif void spiInit(){ from_mbed.format(16,3); @@ -25,31 +25,38 @@ from_mbed.frequency(1000000); from_gyro.frequency(1000000); } - + void spi_mbed(){ + u16 FM; if(from_mbed.receive()){ - FM=from_mbed.read(); - RR=FM>>15; - LR=FM>>14; - if(RR==1) //右旋回の関数へ - else if(LR==1) //左旋回の関数へ - else if(FM>>13==1){ //コントローラーのX方向成分入力 - speed_X=FM>>7-128; - if(FM>>6==1) speed_Y=FM-128; - else speed_Y=FM; + FM=from_mbed.read(); + RR=FM>>15; + LR=FM>>14; + if(RR==1){ + } //右旋回の関数へ + else if(LR==1){ + } //左旋回の関数へ + else if(FM>>13==1){ //コントローラーのX方向成分入力 + speed_X=FM>>7; + speed_X=FM-128; + if(FM>>6==1) speed_Y=FM-128; + else speed_Y=FM; } - else{ - speed_X=FM>>7*(-1); - if(FM>>6==1) speed_Y=FM-128; - else speed_Y=FM; - } + else{ + speed_X=FM>>7; + speed_Y=(-1)*speed_Y; + if(FM>>6==1) speed_Y=FM-128; + else speed_Y=FM; + } } + } + void getGyro(){ u16 data; - if(from_gyro.receive()) { - data = gyro_gyro.read(); + if(from_gyro.receive()){ + data = from_gyro.read(); if(data >> 15) angle = -(data & 0x7fff); else angle = data & 0x7fff; now_angle = (double)angle / 10; + } } -} \ No newline at end of file