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: OSL10564_74HC595 mbed
main.cpp
00001 /* 00002 * Mbed Application program / Akizuki 7-segment LED driver [OSL10564-74HC595-x] 00003 * AKIZUKI AE-7SEG-BOARD-KIT-BLUE 00004 * http://akizukidenshi.com/catalog/g/gK-10344/ 00005 * 00006 * Copyright (c) 2018 Kenji Arai / JH1PJL 00007 * http://www.page.sannet.ne.jp/kenjia/index.html 00008 * http://mbed.org/users/kenjiArai/ 00009 * Created: January 7th, 2018 00010 * Revised: January 22nd, 2018 00011 */ 00012 00013 // Include -------------------------------------------------------------------- 00014 #include "mbed.h" 00015 #include "7segLed_HC595.h" 00016 00017 // Definition ----------------------------------------------------------------- 00018 #define NUM_OF_DIGIT 6 00019 00020 #define KEYIN_THEN_EXIT_WHILE() {if(exit_while_loop_when_keyinput()){ break;}} 00021 00022 // Constructor ---------------------------------------------------------------- 00023 Serial pc(USBTX, USBRX); 00024 #if defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F411RE)\ 00025 || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_L152RE)\ 00026 || defined(TARGET_NUCLEO_L073RZ) || defined(TARGET_NUCLEO_L053R8)\ 00027 || defined(TARGET_NUCLEO_L476RG) 00028 // SPI MOSI,SCLK,any port, PWM, number of digit 00029 SevenSegLed led_7segs(D4, D3, D5, D6, NUM_OF_DIGIT); 00030 #elif defined(TARGET_NUCLEO_F334R8) 00031 // SPI MOSI,SCLK,any port, PWM, number of digit 00032 SevenSegLed led_7segs(D4, D3, D5, D7, NUM_OF_DIGIT); 00033 #elif defined(TARGET_NUCLEO_F303K8) 00034 // SPI MOSI,SCLK,any port, PWM, number of digit 00035 SevenSegLed led_7segs(A6, A4, A5, A3, NUM_OF_DIGIT); 00036 #elif TARGET_Freescale 00037 // SPI MOSI,SCLK,any port, PWM, number of digit 00038 SevenSegLed led_7segs(D11, D13, D12, D10, NUM_OF_DIGIT); 00039 #else 00040 #error "Please set your own SevenSegLed constractor!" 00041 #endif 00042 DigitalOut myled(LED1); 00043 AnalogIn vol(A0); 00044 00045 // RAM ------------------------------------------------------------------------ 00046 time_t seconds; 00047 00048 // ROM / Constant data -------------------------------------------------------- 00049 00050 // Function prototypes -------------------------------------------------------- 00051 bool exit_while_loop_when_keyinput(void); 00052 00053 //------------------------------------------------------------------------------ 00054 // Control Program 00055 //------------------------------------------------------------------------------ 00056 int main() 00057 { 00058 //-------------------------------------------------------------------------- 00059 pc.printf("Hit any key to go next step\r\n"); 00060 pc.printf("Step1\r\n"); 00061 { 00062 uint32_t max = 9; 00063 for (uint32_t i = 1; i < NUM_OF_DIGIT; i++) { 00064 max = max * 10 + 9; 00065 } 00066 pc.printf("max = %d\r\n", max); 00067 led_7segs.zero_suppress(true); 00068 int32_t count = 0; 00069 while(true) { 00070 led_7segs = count++; 00071 if (count > max) { 00072 count = 0; 00073 } 00074 float wait_time = 5.0f / (float)(count + 1); 00075 if (wait_time > 0.01f) { 00076 wait(wait_time); 00077 } 00078 KEYIN_THEN_EXIT_WHILE(); 00079 } 00080 } 00081 //-------------------------------------------------------------------------- 00082 pc.printf("Step2\r\n"); 00083 { 00084 char buf[16]; 00085 00086 led_7segs.zero_suppress(false); 00087 float led_bright = 0.5f; 00088 while(true) { 00089 time_t seconds = time(NULL); 00090 strftime(buf, 10, "%H.%M.%S", localtime(&seconds)); 00091 //strftime(buf, 10, "1.2.3.4.%S", localtime(&seconds)); 00092 pc.printf("%s\r\n", buf); 00093 led_7segs.put_ascii(buf); 00094 led_7segs.brightness(led_bright); 00095 if (led_bright == 0.5f) { 00096 led_bright = 1.0f; 00097 } else { 00098 led_bright = 0.5f; 00099 } 00100 wait(1.0f); 00101 KEYIN_THEN_EXIT_WHILE(); 00102 } 00103 } 00104 //-------------------------------------------------------------------------- 00105 pc.printf("Step3\r\n"); 00106 { 00107 uint8_t seg_bf[6] = { 00108 0b00000001 // LSB 00109 ,0b00000010 00110 ,0b10000100 // +Dot 00111 ,0b00001000 00112 ,0b00010000 00113 ,0b00100000 // MSB 00114 }; 00115 00116 led_7segs.zero_suppress(true); 00117 led_7segs.brightness(1.0f); 00118 int32_t count = 0; 00119 while(true) { 00120 count++; 00121 if (count & 0x01) { 00122 led_7segs.put_raw(seg_bf); 00123 } else { 00124 led_7segs.put_ascii("12.34567"); 00125 } 00126 wait(1.0f); 00127 KEYIN_THEN_EXIT_WHILE(); 00128 } 00129 } 00130 //-------------------------------------------------------------------------- 00131 pc.printf("Step4\r\n"); 00132 { 00133 char buf[16]; 00134 00135 for (uint32_t i = 0; i < sizeof(buf); i++) { 00136 buf[i] = ' '; 00137 } 00138 bool exit_req = false; 00139 while(true) { 00140 for (uint32_t n = ' '; n < '~'; n++) { 00141 for (uint32_t i = 0 ; i < sizeof(buf) - 1; i++) { 00142 buf[i] = buf[i + 1]; 00143 } 00144 buf[NUM_OF_DIGIT - 1] = n; 00145 pc.putc(n); 00146 led_7segs.put_strings(buf); 00147 led_7segs.brightness(vol); 00148 wait(1.0f); 00149 if(exit_while_loop_when_keyinput()) { 00150 exit_req = true; 00151 break; 00152 } 00153 } 00154 if (exit_req == true) { 00155 break; 00156 } 00157 } 00158 for (uint32_t i = 0; i < sizeof(buf); i++) { 00159 buf[i] = ' '; 00160 } 00161 led_7segs.put_strings(buf); 00162 pc.printf("\r\n"); 00163 } 00164 //-------------------------------------------------------------------------- 00165 pc.printf("Step5\r\n"); 00166 { 00167 char buf[16]; 00168 00169 pc.printf("hit [Esc] to exit the function\r\n"); 00170 for (uint32_t i = 0; i < sizeof(buf); i++) { 00171 buf[i] = ' '; 00172 } 00173 led_7segs.put_strings(buf); 00174 while(true) { 00175 while(pc.readable() == 0) { 00176 ; 00177 } 00178 char c = pc.getc(); 00179 pc.putc(c); 00180 if (c == 0x1b) { // [Esc] 00181 break; 00182 } 00183 for (uint32_t i = 0 ; i < sizeof(buf) - 1; i++) { 00184 buf[i] = buf[i + 1]; 00185 } 00186 buf[NUM_OF_DIGIT - 1] = c; 00187 led_7segs.put_strings(buf); 00188 } 00189 for (uint32_t i = 0; i < sizeof(buf); i++) { 00190 buf[i] = ' '; 00191 } 00192 led_7segs.put_strings(buf); 00193 pc.printf("\r\n"); 00194 } 00195 //-------------------------------------------------------------------------- 00196 pc.printf("Step_END\r\n"); 00197 { 00198 while(true) { 00199 pc.printf("Finished -> Reset then start again\r\n"); 00200 wait(10.0f); 00201 } 00202 } 00203 } 00204 00205 bool exit_while_loop_when_keyinput(void) 00206 { 00207 if (pc.readable()) { 00208 while(pc.readable()) { 00209 char c = pc.getc(); 00210 } 00211 return true; 00212 } else { 00213 return false; 00214 } 00215 }
Generated on Fri Aug 12 2022 11:53:31 by
1.7.2