A program to measure the temperature using the Max6675 board. The temperature is shown on 8x8 Max7219 matrix display and it is saved on SD as well.
Dependencies: MAX7219 SDFileSystem mbed
Fork of MAXREFDES99_demo by
The program measures the temperature using the Max6675 board designed for Arduino. The temperature is shown on Max7219 8x8 matrix display (designed for Arduino as well) as text marque from right to left. The fonf size is 5x7 so the last row is used to show some info:
- All leds off: Normal temperature measuring - Leds shifting: Saving on SD card - Leds blinking: SD card missing or damaged
The Blue "user button" is used to save measured temperature on SD card. First click start saving, the second stop the process. Together the temperature is saved also the time. The time is reset when the process start. Connecting the USB to PC it's possible to see instant temperature and all saved data on SD.
main.cpp@3:41bdbc9b3cec, 2016-04-11 (annotated)
- Committer:
- pradipv
- Date:
- Mon Apr 11 16:19:13 2016 +0000
- Revision:
- 3:41bdbc9b3cec
- Parent:
- 0:6b0161c3e440
- Child:
- 6:00aabe967e51
version 0.1, updated with 16x16 font data and code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:6b0161c3e440 | 1 | /*********************************************************************** |
j3 | 0:6b0161c3e440 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:6b0161c3e440 | 3 | * |
j3 | 0:6b0161c3e440 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:6b0161c3e440 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:6b0161c3e440 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 0:6b0161c3e440 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:6b0161c3e440 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:6b0161c3e440 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:6b0161c3e440 | 10 | * |
j3 | 0:6b0161c3e440 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 0:6b0161c3e440 | 12 | * in all copies or substantial portions of the Software. |
j3 | 0:6b0161c3e440 | 13 | * |
j3 | 0:6b0161c3e440 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:6b0161c3e440 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:6b0161c3e440 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:6b0161c3e440 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:6b0161c3e440 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:6b0161c3e440 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:6b0161c3e440 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:6b0161c3e440 | 21 | * |
j3 | 0:6b0161c3e440 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:6b0161c3e440 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:6b0161c3e440 | 24 | * Products, Inc. Branding Policy. |
j3 | 0:6b0161c3e440 | 25 | * |
j3 | 0:6b0161c3e440 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 0:6b0161c3e440 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:6b0161c3e440 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:6b0161c3e440 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:6b0161c3e440 | 30 | * ownership rights. |
j3 | 0:6b0161c3e440 | 31 | **********************************************************************/ |
j3 | 0:6b0161c3e440 | 32 | |
j3 | 0:6b0161c3e440 | 33 | #include "maxrefdes99.h" |
j3 | 0:6b0161c3e440 | 34 | |
j3 | 0:6b0161c3e440 | 35 | int main(void) |
j3 | 0:6b0161c3e440 | 36 | { |
j3 | 0:6b0161c3e440 | 37 | Max7219 display(D11, D12, D13, D10); |
j3 | 0:6b0161c3e440 | 38 | |
j3 | 0:6b0161c3e440 | 39 | //struct for holding MAX7219 configuration data |
j3 | 0:6b0161c3e440 | 40 | max7219_configuration_t display_config; |
j3 | 0:6b0161c3e440 | 41 | |
j3 | 0:6b0161c3e440 | 42 | //configuration data |
j3 | 0:6b0161c3e440 | 43 | display_config.decode_mode = 0; //no BCD decode |
j3 | 0:6b0161c3e440 | 44 | display_config.intensity = 0x0F; //max intensity |
j3 | 0:6b0161c3e440 | 45 | display_config.scan_limit = 0x07; //scan all digits |
j3 | 0:6b0161c3e440 | 46 | |
j3 | 0:6b0161c3e440 | 47 | //set number of MAX7219 devices being used |
j3 | 0:6b0161c3e440 | 48 | display.set_num_devices(4); |
j3 | 0:6b0161c3e440 | 49 | |
j3 | 0:6b0161c3e440 | 50 | //config display |
j3 | 0:6b0161c3e440 | 51 | display.init_display(display_config); |
j3 | 0:6b0161c3e440 | 52 | |
j3 | 0:6b0161c3e440 | 53 | //ensure all data registers are 0 |
j3 | 0:6b0161c3e440 | 54 | display.display_all_off(); |
j3 | 0:6b0161c3e440 | 55 | |
j3 | 0:6b0161c3e440 | 56 | display.enable_display(); |
j3 | 0:6b0161c3e440 | 57 | |
pradipv | 3:41bdbc9b3cec | 58 | uint32_t user_input = 0,user_font = 0; |
j3 | 0:6b0161c3e440 | 59 | uint32_t shift_right; |
j3 | 0:6b0161c3e440 | 60 | char user_char; |
j3 | 0:6b0161c3e440 | 61 | char *p_str; |
j3 | 0:6b0161c3e440 | 62 | |
j3 | 0:6b0161c3e440 | 63 | while(user_input != 9) |
j3 | 0:6b0161c3e440 | 64 | { |
j3 | 0:6b0161c3e440 | 65 | user_input = print_menu(); |
j3 | 0:6b0161c3e440 | 66 | |
j3 | 0:6b0161c3e440 | 67 | switch(user_input) |
j3 | 0:6b0161c3e440 | 68 | { |
pradipv | 3:41bdbc9b3cec | 69 | |
pradipv | 3:41bdbc9b3cec | 70 | case 1: |
pradipv | 3:41bdbc9b3cec | 71 | |
pradipv | 3:41bdbc9b3cec | 72 | user_font = get_user_input("\nPlease enter 0 to use 5x7 font or 1 to use 16x16 font: ", 1); |
pradipv | 3:41bdbc9b3cec | 73 | break; |
pradipv | 3:41bdbc9b3cec | 74 | |
pradipv | 3:41bdbc9b3cec | 75 | case 2: |
j3 | 0:6b0161c3e440 | 76 | |
j3 | 0:6b0161c3e440 | 77 | user_input = get_user_input("\nPlease enter a value from 0 to 15: ", 15); |
j3 | 0:6b0161c3e440 | 78 | |
j3 | 0:6b0161c3e440 | 79 | printf("\nUpdating display configuration...\n"); |
j3 | 0:6b0161c3e440 | 80 | |
j3 | 0:6b0161c3e440 | 81 | display_config.intensity = user_input; |
j3 | 0:6b0161c3e440 | 82 | |
j3 | 0:6b0161c3e440 | 83 | display.init_display(display_config); |
j3 | 0:6b0161c3e440 | 84 | |
j3 | 0:6b0161c3e440 | 85 | //make sure is good for next loop |
j3 | 0:6b0161c3e440 | 86 | user_input = 0; |
j3 | 0:6b0161c3e440 | 87 | |
j3 | 0:6b0161c3e440 | 88 | break; |
j3 | 0:6b0161c3e440 | 89 | |
pradipv | 3:41bdbc9b3cec | 90 | case 3: |
pradipv | 3:41bdbc9b3cec | 91 | |
pradipv | 3:41bdbc9b3cec | 92 | if(user_font==0) |
pradipv | 3:41bdbc9b3cec | 93 | user_input = get_user_input("\nPlease enter which position, 1 to 32: ", 32); |
pradipv | 3:41bdbc9b3cec | 94 | |
pradipv | 3:41bdbc9b3cec | 95 | user_char = get_user_char("\nPlease enter an ASCII character from '0' (zero) to 'z' (0x7A): "); |
j3 | 0:6b0161c3e440 | 96 | |
pradipv | 3:41bdbc9b3cec | 97 | if(user_font==0) |
pradipv | 3:41bdbc9b3cec | 98 | print_char(&display, user_input, user_char); |
pradipv | 3:41bdbc9b3cec | 99 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 100 | print_char_16x16(&display, 0, user_char); |
pradipv | 3:41bdbc9b3cec | 101 | |
j3 | 0:6b0161c3e440 | 102 | //make sure is good for next loop |
j3 | 0:6b0161c3e440 | 103 | user_input = 0; |
j3 | 0:6b0161c3e440 | 104 | |
j3 | 0:6b0161c3e440 | 105 | break; |
j3 | 0:6b0161c3e440 | 106 | |
pradipv | 3:41bdbc9b3cec | 107 | case 4: |
j3 | 0:6b0161c3e440 | 108 | |
pradipv | 3:41bdbc9b3cec | 109 | if(user_font==0) |
j3 | 0:6b0161c3e440 | 110 | user_input = get_user_input("\nPlease enter which position, 1 to 32: ", 32); |
pradipv | 3:41bdbc9b3cec | 111 | |
j3 | 0:6b0161c3e440 | 112 | p_str = get_user_string("\nPlease enter a string less than 24 characters: "); |
j3 | 0:6b0161c3e440 | 113 | |
pradipv | 3:41bdbc9b3cec | 114 | if(user_font==0) |
pradipv | 3:41bdbc9b3cec | 115 | print_string(&display, user_input, p_str); |
pradipv | 3:41bdbc9b3cec | 116 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 117 | print_string_16x16(&display,p_str); |
pradipv | 3:41bdbc9b3cec | 118 | |
j3 | 0:6b0161c3e440 | 119 | //make sure is good for next loop |
j3 | 0:6b0161c3e440 | 120 | user_input = 0; |
j3 | 0:6b0161c3e440 | 121 | |
j3 | 0:6b0161c3e440 | 122 | break; |
j3 | 0:6b0161c3e440 | 123 | |
pradipv | 3:41bdbc9b3cec | 124 | case 5: |
j3 | 0:6b0161c3e440 | 125 | |
pradipv | 3:41bdbc9b3cec | 126 | if(user_font==0) |
pradipv | 3:41bdbc9b3cec | 127 | user_input = get_user_input("\nPlease enter number of shifts, 1 to 32: ", 32); |
pradipv | 3:41bdbc9b3cec | 128 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 129 | user_input = get_user_input("\nPlease enter number of shifts, 1 to 96: ", 96); |
pradipv | 3:41bdbc9b3cec | 130 | |
pradipv | 3:41bdbc9b3cec | 131 | shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right: ", 1); |
j3 | 0:6b0161c3e440 | 132 | |
j3 | 0:6b0161c3e440 | 133 | if(shift_right) |
j3 | 0:6b0161c3e440 | 134 | { |
j3 | 0:6b0161c3e440 | 135 | printf("\nShifting Display Right %d positions\n", user_input); |
pradipv | 3:41bdbc9b3cec | 136 | if(user_font==0) |
pradipv | 3:41bdbc9b3cec | 137 | shift_display_right(&display, user_input, 100); |
pradipv | 3:41bdbc9b3cec | 138 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 139 | shift_display_right_16x16(&display, user_input, 100); |
j3 | 0:6b0161c3e440 | 140 | } |
j3 | 0:6b0161c3e440 | 141 | else |
j3 | 0:6b0161c3e440 | 142 | { |
j3 | 0:6b0161c3e440 | 143 | printf("\nShifting Display Left %d positions\n", user_input); |
pradipv | 3:41bdbc9b3cec | 144 | if(user_font==0) |
pradipv | 3:41bdbc9b3cec | 145 | shift_display_left(&display, user_input, 100); |
pradipv | 3:41bdbc9b3cec | 146 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 147 | shift_display_left_16x16(&display, user_input, 100); |
pradipv | 3:41bdbc9b3cec | 148 | |
j3 | 0:6b0161c3e440 | 149 | } |
j3 | 0:6b0161c3e440 | 150 | |
j3 | 0:6b0161c3e440 | 151 | break; |
j3 | 0:6b0161c3e440 | 152 | |
pradipv | 3:41bdbc9b3cec | 153 | case 6: |
j3 | 0:6b0161c3e440 | 154 | |
j3 | 0:6b0161c3e440 | 155 | all_off(&display); |
j3 | 0:6b0161c3e440 | 156 | |
j3 | 0:6b0161c3e440 | 157 | break; |
j3 | 0:6b0161c3e440 | 158 | |
pradipv | 3:41bdbc9b3cec | 159 | case 7: |
j3 | 0:6b0161c3e440 | 160 | |
j3 | 0:6b0161c3e440 | 161 | printf("\nRunning Demo\n"); |
pradipv | 3:41bdbc9b3cec | 162 | if(user_font==0) |
j3 | 0:6b0161c3e440 | 163 | demo(&display, display_config, false); |
pradipv | 3:41bdbc9b3cec | 164 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 165 | demo_16x16(&display, display_config, false); |
j3 | 0:6b0161c3e440 | 166 | |
j3 | 0:6b0161c3e440 | 167 | break; |
pradipv | 3:41bdbc9b3cec | 168 | |
j3 | 0:6b0161c3e440 | 169 | case 8: |
j3 | 0:6b0161c3e440 | 170 | |
j3 | 0:6b0161c3e440 | 171 | //blocking case, endless loop |
pradipv | 3:41bdbc9b3cec | 172 | shift_right = get_user_input("\nWhich direction? 0 for left, 1 for right: ", 1); |
pradipv | 3:41bdbc9b3cec | 173 | if(user_font==0) |
j3 | 0:6b0161c3e440 | 174 | endless_scroll_display(&display, shift_right); |
pradipv | 3:41bdbc9b3cec | 175 | else if(user_font==1) |
pradipv | 3:41bdbc9b3cec | 176 | endless_scroll_display_16x16(&display, shift_right); |
j3 | 0:6b0161c3e440 | 177 | |
j3 | 0:6b0161c3e440 | 178 | break; |
j3 | 0:6b0161c3e440 | 179 | |
j3 | 0:6b0161c3e440 | 180 | case 9: |
pradipv | 3:41bdbc9b3cec | 181 | printf("\nEnding Program\n"); |
j3 | 0:6b0161c3e440 | 182 | break; |
j3 | 0:6b0161c3e440 | 183 | |
j3 | 0:6b0161c3e440 | 184 | default: |
j3 | 0:6b0161c3e440 | 185 | printf("\nInvalid entry, please try again\n"); |
j3 | 0:6b0161c3e440 | 186 | break; |
j3 | 0:6b0161c3e440 | 187 | } |
j3 | 0:6b0161c3e440 | 188 | } |
j3 | 0:6b0161c3e440 | 189 | |
j3 | 0:6b0161c3e440 | 190 | return 0; |
j3 | 0:6b0161c3e440 | 191 | } |
pradipv | 3:41bdbc9b3cec | 192 |