2017_Bteam_jushinkun_kai

Dependencies:   gamma_controller mbed serial_2017

Committer:
Komazawa_sun
Date:
Tue Jun 27 07:56:51 2017 +0000
Revision:
0:cf9afbdbedd8
2017_Bteam_jushinkun

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Komazawa_sun 0:cf9afbdbedd8 1 #include "mbed.h"
Komazawa_sun 0:cf9afbdbedd8 2 #include "gamma_ctrl.h"
Komazawa_sun 0:cf9afbdbedd8 3 #define I2C_SDA dp5
Komazawa_sun 0:cf9afbdbedd8 4 #define I2C_SCL dp27
Komazawa_sun 0:cf9afbdbedd8 5
Komazawa_sun 0:cf9afbdbedd8 6 DigitalOut read_success_led(LED1);
Komazawa_sun 0:cf9afbdbedd8 7 DigitalOut read_error_led(LED2);
Komazawa_sun 0:cf9afbdbedd8 8 I2CSlave transmit(I2C_SDA,I2C_SCL);
Komazawa_sun 0:cf9afbdbedd8 9 gamma_ctrl twe(115200);
Komazawa_sun 0:cf9afbdbedd8 10 void status_led();
Komazawa_sun 0:cf9afbdbedd8 11 void i2c_send();
Komazawa_sun 0:cf9afbdbedd8 12
Komazawa_sun 0:cf9afbdbedd8 13 int main()
Komazawa_sun 0:cf9afbdbedd8 14 {
Komazawa_sun 0:cf9afbdbedd8 15 transmit.address(GAMMA_ADDRESS);
Komazawa_sun 0:cf9afbdbedd8 16 while(1)
Komazawa_sun 0:cf9afbdbedd8 17 {
Komazawa_sun 0:cf9afbdbedd8 18 twe.get_data();
Komazawa_sun 0:cf9afbdbedd8 19 status_led();
Komazawa_sun 0:cf9afbdbedd8 20 i2c_send();
Komazawa_sun 0:cf9afbdbedd8 21 /*printf("status:%d",twe.error_status);
Komazawa_sun 0:cf9afbdbedd8 22 printf(",rx:%d,ry:%d,r,%d%d%d%d",twe.pack.data.rx,twe.pack.data.ry,
Komazawa_sun 0:cf9afbdbedd8 23 twe.pack.data.r_sw1,twe.pack.data.r_sw2,
Komazawa_sun 0:cf9afbdbedd8 24 twe.pack.data.r_sw3,twe.pack.data.r_sw4);
Komazawa_sun 0:cf9afbdbedd8 25 printf("\r\n");*/
Komazawa_sun 0:cf9afbdbedd8 26 wait(0.1); //wait変えないで
Komazawa_sun 0:cf9afbdbedd8 27 }
Komazawa_sun 0:cf9afbdbedd8 28 }
Komazawa_sun 0:cf9afbdbedd8 29
Komazawa_sun 0:cf9afbdbedd8 30 void status_led()
Komazawa_sun 0:cf9afbdbedd8 31 {
Komazawa_sun 0:cf9afbdbedd8 32 if(twe.error_status == 0)
Komazawa_sun 0:cf9afbdbedd8 33 {
Komazawa_sun 0:cf9afbdbedd8 34 read_error_led = 0;
Komazawa_sun 0:cf9afbdbedd8 35 read_success_led = 1;
Komazawa_sun 0:cf9afbdbedd8 36 }
Komazawa_sun 0:cf9afbdbedd8 37 else
Komazawa_sun 0:cf9afbdbedd8 38 {
Komazawa_sun 0:cf9afbdbedd8 39 read_error_led = 1;
Komazawa_sun 0:cf9afbdbedd8 40 read_success_led = 0;
Komazawa_sun 0:cf9afbdbedd8 41 }
Komazawa_sun 0:cf9afbdbedd8 42 }
Komazawa_sun 0:cf9afbdbedd8 43
Komazawa_sun 0:cf9afbdbedd8 44 void i2c_send()
Komazawa_sun 0:cf9afbdbedd8 45 {
Komazawa_sun 0:cf9afbdbedd8 46 if(transmit.receive() == I2CSlave::ReadAddressed){
Komazawa_sun 0:cf9afbdbedd8 47 transmit.write(twe.pack.all_data,GAMMA_DATA_SIZE - 1);
Komazawa_sun 0:cf9afbdbedd8 48 }
Komazawa_sun 0:cf9afbdbedd8 49 }