for textbook v4.4

Dependencies:   mbed HEPTA_CDH

Committer:
Yanagihara
Date:
Tue Nov 17 03:38:18 2020 +0000
Revision:
27:210fe762fa94
Parent:
26:f15b873a018c
"puts" to "pc.puts"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
HeptaSatTraining2019 25:5fd40a170032 2 #include "HEPTA_CDH.h"
HeptaSatTraining2019 26:f15b873a018c 3
umeume 2:1c5cdb2c3e0f 4 Serial pc(USBTX,USBRX);
HeptaSatTraining2019 26:f15b873a018c 5 HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
HeptaSatTraining2019 26:f15b873a018c 6
umeume 2:1c5cdb2c3e0f 7 int main()
umeume 2:1c5cdb2c3e0f 8 {
HeptaSatTraining2019 26:f15b873a018c 9 pc.baud(9600);
HeptaSatTraining2019 26:f15b873a018c 10 pc.printf("Hello world!\r\n");
HeptaSatTraining2019 26:f15b873a018c 11 char str[100];
HeptaSatTraining2019 26:f15b873a018c 12 mkdir("/sd/mydir", 0777);
HeptaSatTraining2019 26:f15b873a018c 13 FILE *fp = fopen("/sd/mydir/test.txt","w");
HeptaSatTraining2019 26:f15b873a018c 14 if(fp == NULL) {
HeptaSatTraining2019 26:f15b873a018c 15 error("Could not open file for write\r\n");
HeptaSatTraining2019 26:f15b873a018c 16 }
HeptaSatTraining2019 26:f15b873a018c 17 for(int i=0; i<10; i++)fprintf(fp,"Hello my name is HEPTA!\r\n");
HeptaSatTraining2019 26:f15b873a018c 18 fclose(fp);
HeptaSatTraining2019 26:f15b873a018c 19 fp = fopen("/sd/mydir/test.txt","r");
HeptaSatTraining2019 26:f15b873a018c 20 for(int j = 0; j < 10; j++) {
HeptaSatTraining2019 26:f15b873a018c 21 fgets(str,100,fp);
Yanagihara 27:210fe762fa94 22 pc.puts(str);
HeptaSatTraining2019 26:f15b873a018c 23 }
HeptaSatTraining2019 26:f15b873a018c 24 fclose(fp);
HeptaSatTraining2019 26:f15b873a018c 25 pc.printf("Goodbye!!\r\n");
umeume 2:1c5cdb2c3e0f 26 }