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: Ping SDFileSystem mbed-src
Revision 0:2f48b11b154f, committed 2015-12-31
- Comitter:
- lilac0112_1
- Date:
- Thu Dec 31 05:16:23 2015 +0000
- Child:
- 1:7070fb876a2c
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ping.lib Thu Dec 31 05:16:23 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/rosienej/code/Ping/#e252ca27589b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Thu Dec 31 05:16:23 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/def.h Thu Dec 31 05:16:23 2015 +0000 @@ -0,0 +1,30 @@ +#ifndef _DEF_H_ +#define _DEF_H_ + +//#define SD_CARD +//#define ULTRA_SONIC//HC-SR04 +//#define COLOR_SENSOR//S9706→required for changing to S9032 +#define IR_SENSOR//MCP3208 + + + + +#ifdef SD_CARD + #define BUFSIZE 40 + #define FDATA_NUM 10 +#endif /*SD_CARD*/ + +#ifdef ULTRA_SONIC + +#endif /*ULTRA_SONIC*/ + +#ifdef COLOR_SENSOR + #define SENSOR_NUM 3; +#endif /*COLOR_SENSOR*/ + +#ifdef IR_SENSOR + #define IC_NUM 3 + #define CH_NUM 8 +#endif /*IR_SENSOR*/ + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extern.h Thu Dec 31 05:16:23 2015 +0000 @@ -0,0 +1,34 @@ +#ifndef _EXTERN_H_ +#define _EXTERN_H_ + +#include "def.h" + +/*追加ライブラリ*/ +#include "SDFileSystem.h" +#include "Ping.h" + +#include "format.h" +/*クラス,ピン宣言等*/ +#ifdef SD_CARD +extern SDFileSystem sd; +extern SPISlave nucleo; +#endif /*SD_CARD*/ + +#ifdef ULTRA_SONIC +extern Ping rear; +extern Ping front; +extern SPISlave nucleo; +#endif /*ULTRA_SONIC*/ + +#ifdef COLOR_SENSOR +extern AnalogIn ColorSensor[][]; +extern SPISlave nucleo; +#endif /*COLOR_SENSOR*/ + +#ifdef IR_SENSOR +extern SPI ir; +extern DigitalOut cs[]; +extern SPISlave nucleo; +#endif /*IR_SENSOR*/ + +#endif /*_EXTERN_H_*/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/format.cpp Thu Dec 31 05:16:23 2015 +0000
@@ -0,0 +1,198 @@
+#include "mbed.h"
+#include "extern.h"
+
+#ifdef SD_CARD
+void Sd_System(void){
+
+ char buf[BUFSIZE];
+ uint16_t FileData[FDATA_NUM]={0}, num, data;
+ uint8_t spi_num, h_byte, l_byte;
+ uint16_t spi_data;
+ int i;
+ FILE *fp;
+ pc.printf("Hello World!\n");
+
+ mkdir("/sd/mydir", 0777);
+
+ while(1){
+
+ val = nucleo.receive();
+ if(!val) return;
+
+ spi_num = device.read();
+ h_byte = device.read();
+ l_byte = device.read();
+
+ if((spi_num&0x80)>>7 == 1){
+
+ }
+ else{
+
+ }
+ if(val) {
+
+ packet = (front_dis&0x00FF);
+ nucleo.reply(packet);
+ packet = (front_dis&0xFF00)>>8;
+ nucleo.reply(packet);
+ packet = (rear_dis&0x00FF);
+ nucleo.reply(packet);
+ packet = (rear_dis&0xFF00)>>8;
+ nucleo.reply(packet);
+ }
+ // example writing to SD card, sford
+
+ fp = fopen("/sd/mydir/sdtest.txt", "r");
+ if(fp == NULL) {
+ error("Could not open file for read\n");
+ }
+ while(fgets(buf, sizeof(buf), fp) != NULL){
+ if(buf[0] == '#') continue;
+
+ num = atol(strtok(buf, ","));
+ data = atol(strtok(NULL, "\r\n\0"));
+
+ if((num>=0)&&(num<FDATA_NUM)){
+ FileData[num] = data;
+ pc.printf("%d, %ld\n", num, FileData[num]);
+ }
+ else{
+ continue;
+ }
+ }
+ fclose(fp);
+
+ FileData[0] = 1;
+ FileData[1] = 2;
+ FileData[2] = 5;
+ FileData[3] = 10;
+ FileData[4] = 20;
+ FileData[5] = 50;
+ FileData[6] = 10;
+ FileData[7] = 20;
+ FileData[8] = 50;
+ FileData[9] = 100;
+
+ fp = fopen("/sd/mydir/sdtest.txt", "w");
+ for(i=0; i<FDATA_NUM; i++) fprintf(fp, "%d, %ld\n", i, FileData[i]);
+ fclose(fp);
+
+ //pc.printf("Goodbye World!\n");
+ }
+}
+#endif /*SD_CARD*/
+
+#ifdef ULTRA_SONIC
+void Usw_System(void){
+ uint8_t paket, val, order;
+ uint16_t front_dis=0, rear_dis=0;
+
+ while(1){
+ front.Send();
+ wait_ms(30);
+ front_dis = front.Read_cm();
+
+ rear.Send();
+ wait_ms(30);
+ rear_dis = rear.Read_cm();
+
+ while(1){
+ val = nucleo.receive();
+ if(val){
+ order = nucleo.read();
+ switch(order){
+ case 0x01:
+ packet = (front_dis&0x00FF);break;
+ case 0x02:
+ packet = (front_dis&0xFF00)>>8;break;
+ case 0x03:
+ packet = (rear_dis&0x00FF);break;
+ case 0x04:
+ packet = (rear_dis&0xFF00)>>8;break;
+ default:
+ packet = 0x00;break;
+ }
+ nucleo.reply(packet);
+ }
+ else{
+ break;
+ }
+ }
+ }
+}
+#endif /*ULTRA_SONIC*/
+
+#ifdef COLOR_SENSOR
+void Color_System(void){
+
+ while(1){
+
+ ColorSensor[0]
+ }
+}
+#endif /*COLOR_SENSOR*/
+
+#ifdef IR_SENSOR
+void Ir_System(void){
+
+ static uint8_t const START_BIT = 0x04;
+ static uint8_t const MODE_SINGLE = 0x02; // Single-ended mode
+ //static uint8_t const MODE_DIFF = 0x00; // Differential mode
+
+ static uint8_t const IR_NUM[IC_NUM] = {6, 6, 8};
+
+ uint8_t ic, ch;
+ unsigned int command_high, command_low;
+ unsigned int high_byte, low_byte;
+
+ uint8_t packet, val, order;
+
+ uint16_t ir_data[IC_NUM][CH_NUM];
+
+ ir.frequency(1000000);
+
+ for(ic=0; ic<IC_NUM; ic++) cs[ic]=1;
+ while(1) {
+ for(ic=0; ic<IC_NUM; ic++){//IC
+ for(ch=0; ch<IR_NUM[ic]; ch++){//Ch
+ command_high = START_BIT | MODE_SINGLE | ((ch & 0x04) >> 2);
+ command_low = (ch & 0x03) << 6;
+
+ cs[ic] = 0;
+
+ ir.write(command_high);
+ high_byte = ir.write(command_low) & 0x0F;
+ low_byte = ir.write(0);
+
+ cs[ic] = 1;
+ wait_us(1);
+
+ //ir_data[ic][ch] = (high_byte << 8) | low_byte;
+ ir_data[ic][ch] = ((high_byte << 4) | (low_byte >> 4))&0xFF;
+ }
+ }
+ while(1){
+ val = nucleo.receive();
+ if(val){
+ order = nucleo.read();
+ packet = ir_data[order/10][order%10] & 0x00FF;
+ nucleo.reply(packet);
+ //for(ic=0; ic<IC_NUM; ic++){//IC
+ // for(ch=0; ch<IR_NUM[ic]; ch++){//Ch
+ // packet = ir_data[ic][ch] & 0x00FF;
+ // nucleo.reply(packet);
+ // }
+ //}
+ }
+ else{
+ break;
+ }
+ }
+
+ }
+}
+#endif /*IR_SENSOR*/
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/format.h Thu Dec 31 05:16:23 2015 +0000 @@ -0,0 +1,20 @@ +#ifndef _FORMAT_H_ +#define _FORMAT_H_ + +#ifdef SD_CARD +void Sd_System(void); +#endif /*SD_CARD*/ + +#ifdef ULTRA_SONIC +void Usw_System(void); +#endif /*ULTRA_SONIC*/ + +#ifdef COLOR_SENSOR +void Color_System(void); +#endif /*COLOR_SENSOR*/ + +#ifdef IR_SENSOR +void Ir_System(void); +#endif /*IR_SENSOR*/ + +#endif /*_FORMAT_H_*/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Dec 31 05:16:23 2015 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+#include "extern.h"
+#include "main.h"
+
+int main() {
+ nucleo.reply(0x00);
+ while(1) {
+ #ifdef SD_CARD
+ Sd_System();
+ #endif /*SD_CARD*/
+
+ #ifdef ULTRA_SONIC
+ Usw_System();
+ #endif /*ULTRA_SONIC*/
+
+ #ifdef COLOR_SENSOR
+ Color_System();
+ #endif /*COLOR_SENSOR*/
+
+ #ifdef IR_SENSOR
+ Ir_System();
+ #endif /*IR_SENSOR*/
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h Thu Dec 31 05:16:23 2015 +0000
@@ -0,0 +1,89 @@
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+#include "def.h"
+
+#ifdef SD_CARD
+static PinName const TX_PIN = dp10;
+static PinName const RX_PIN = dp11;
+Serial pc(TX_PIN, RX_PIN);
+
+static PinName const SD_MOSI = dp15;
+static PinName const SD_MISO = dp16;
+static PinName const SD_SCLK = dp17;
+static PinName const SD_CS = dp18;
+SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, "sd");
+
+static PinName const MOSI = dp15;
+static PinName const MISO = dp16;
+static PinName const SCLK = dp17;
+static PinName const SSEL = dp18;
+SPISlave nucleo(MOSI, MISO, SCLK, SSEL);
+#endif /*SD_CARD*/
+
+#ifdef ULTRA_SONIC
+static PinName const TX_PIN = dp10;
+static PinName const RX_PIN = dp11;
+Serial pc(TX_PIN, RX_PIN);
+
+static PinName const FRONT = D11;
+static PinName const REAR = D12;
+Ping rear(REAR);
+Ping front(FRONT);
+
+static PinName const MOSI = dp15;
+static PinName const MISO = dp16;
+static PinName const SCLK = dp17;
+static PinName const SSEL = dp18;
+SPISlave nucleo(MOSI, MISO, SCLK, SSEL);
+#endif /*ULTRA_SONIC*/
+
+#ifdef COLOR_SENSOR
+static PinName const TX_PIN = dp10;
+static PinName const RX_PIN = dp11;
+Serial pc(TX_PIN, RX_PIN);
+
+
+static PinName const COLOR00 = dp23;
+static PinName const COLOR01 = dp22;
+static PinName const COLOR02 = dp21;
+
+static PinName const COLOR10 = dp23;
+static PinName const COLOR11 = dp22;
+static PinName const COLOR12 = dp21;
+
+static PinName const COLOR20 = dp23;
+static PinName const COLOR21 = dp22;
+static PinName const COLOR22 = dp21;
+AnalogIn ColorSensor[SENSOR_NUM] = {COLOR0, COLOR1, COLOR2};
+
+static PinName const MOSI = dp15;
+static PinName const MISO = dp16;
+static PinName const SCLK = dp17;
+static PinName const SSEL = dp18;
+SPISlave nucleo(MOSI, MISO, SCLK, SSEL);
+#endif /*COLOR_SENSOR*/
+
+#ifdef IR_SENSOR
+static PinName const TX_PIN = dp10;
+static PinName const RX_PIN = dp11;
+Serial pc(TX_PIN, RX_PIN);
+
+static PinName const IR_MOSI = dp15;
+static PinName const IR_MISO = dp16;
+static PinName const IR_SCLK = dp17;
+static PinName const IR0_CS = dp18;
+static PinName const IR1_CS = dp19;
+static PinName const IR2_CS = dp20;
+
+SPI ir(IR_MOSI, IR_MISO, IR_SCLK);
+DigitalOut cs[IC_NUM] = {IR0_CS, IR1_CS, IR2_CS};
+
+static PinName const MOSI = dp15;
+static PinName const MISO = dp16;
+static PinName const SCLK = dp17;
+static PinName const SSEL = dp18;
+SPISlave nucleo(MOSI, MISO, SCLK, SSEL);
+#endif /*IR_SENSOR*/
+
+#endif /*_MAIN_H_*/
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 31 05:16:23 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c \ No newline at end of file