Example code for the Programmable High-Power Infra-Red Beacon with display Designed for use with the E-Puck and Pi Swarm robots for swarm research A number of preset frequencies (1, 2, 5, 10, 20, 30, 40 and 50Hz), powers (25%, 50%, 75% and 100%), duty-cycles (10%, 25%, 50%, 75% and 90%) are defined, and the chosen mode can be selected by holding the 'SET' button for 1 seconds, then moving through to the correct menu. Use as a basic structure should other functionality be required from the beacon, such as custom flash sequencies or alternating between the wide- and narrow- LEDs.

Dependencies:   mbed

PCB Image: [NB Missing connection from pin 1-4 of display] /media/uploads/jah128/board_fin2.png

Eagle Files: /media/uploads/jah128/irledboard_pro.sch /media/uploads/jah128/irledboard_pro.brd

Corel Draw file for laser-cutting box: /media/uploads/jah128/irbox_3.cdr

Committer:
jah128
Date:
Wed Mar 19 15:09:11 2014 +0000
Revision:
0:d88fd55a27a6
Initial Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:d88fd55a27a6 1 /* University of York Robotics Laboratory MBED Library
jah128 0:d88fd55a27a6 2 * Display Driver for Midas I2C 2x16 Display
jah128 0:d88fd55a27a6 3 * Part number MCCOG21605-D6W-BNMLWI
jah128 0:d88fd55a27a6 4 * Rapid Electronics Cat Number 57-2340 [or 57-2334]
jah128 0:d88fd55a27a6 5 * Farnell Cat Number 2063206 [or 2063205]
jah128 0:d88fd55a27a6 6 *
jah128 0:d88fd55a27a6 7 * File: display.cpp
jah128 0:d88fd55a27a6 8 *
jah128 0:d88fd55a27a6 9 * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York
jah128 0:d88fd55a27a6 10 *
jah128 0:d88fd55a27a6 11 * October 2013
jah128 0:d88fd55a27a6 12 *
jah128 0:d88fd55a27a6 13 */
jah128 0:d88fd55a27a6 14
jah128 0:d88fd55a27a6 15 #include "mbed.h"
jah128 0:d88fd55a27a6 16 #include "display.h"
jah128 0:d88fd55a27a6 17
jah128 0:d88fd55a27a6 18 Display::Display(PinName sda, PinName scl, PinName reset) : Stream("display"), _i2c(sda,scl), _reset(reset) {
jah128 0:d88fd55a27a6 19
jah128 0:d88fd55a27a6 20 }
jah128 0:d88fd55a27a6 21
jah128 0:d88fd55a27a6 22 Display::Display() : Stream("display"), _i2c(p9,p10), _reset(p12) {
jah128 0:d88fd55a27a6 23
jah128 0:d88fd55a27a6 24 }
jah128 0:d88fd55a27a6 25
jah128 0:d88fd55a27a6 26 int Display::i2c_message(char byte){
jah128 0:d88fd55a27a6 27 char bytes [2];
jah128 0:d88fd55a27a6 28 bytes[0]=0x80;
jah128 0:d88fd55a27a6 29 bytes[1]=byte;
jah128 0:d88fd55a27a6 30 int ret=_i2c.write(LCD_ADDRESS,bytes,2);
jah128 0:d88fd55a27a6 31 wait(0.01);
jah128 0:d88fd55a27a6 32 return ret;
jah128 0:d88fd55a27a6 33 }
jah128 0:d88fd55a27a6 34
jah128 0:d88fd55a27a6 35 int Display::disp_putc(int c){
jah128 0:d88fd55a27a6 36 char message [2];
jah128 0:d88fd55a27a6 37 message[0]=0x40;
jah128 0:d88fd55a27a6 38 message[1]=c;
jah128 0:d88fd55a27a6 39 _i2c.write(LCD_ADDRESS,message,2);
jah128 0:d88fd55a27a6 40 wait(0.01);
jah128 0:d88fd55a27a6 41 return c;
jah128 0:d88fd55a27a6 42 }
jah128 0:d88fd55a27a6 43
jah128 0:d88fd55a27a6 44
jah128 0:d88fd55a27a6 45
jah128 0:d88fd55a27a6 46 void Display::init_display(){
jah128 0:d88fd55a27a6 47 //Set initial states: display on, cursor off
jah128 0:d88fd55a27a6 48 display_on = 1;
jah128 0:d88fd55a27a6 49 cursor_on = 0;
jah128 0:d88fd55a27a6 50 blink_on = 0;
jah128 0:d88fd55a27a6 51
jah128 0:d88fd55a27a6 52 _reset=1;
jah128 0:d88fd55a27a6 53 wait(0.02);
jah128 0:d88fd55a27a6 54 //Set reset low
jah128 0:d88fd55a27a6 55 _reset=0;
jah128 0:d88fd55a27a6 56 wait(0.001);
jah128 0:d88fd55a27a6 57 _reset=1;
jah128 0:d88fd55a27a6 58 wait(0.03);
jah128 0:d88fd55a27a6 59 i2c_message(0x38);
jah128 0:d88fd55a27a6 60 i2c_message(0x39);
jah128 0:d88fd55a27a6 61 i2c_message(0x14);
jah128 0:d88fd55a27a6 62 i2c_message(0x79);
jah128 0:d88fd55a27a6 63 i2c_message(0x50);
jah128 0:d88fd55a27a6 64 i2c_message(0x6c);
jah128 0:d88fd55a27a6 65 _set_display();
jah128 0:d88fd55a27a6 66 clear_display();
jah128 0:d88fd55a27a6 67 }
jah128 0:d88fd55a27a6 68
jah128 0:d88fd55a27a6 69 void Display::write_string(char * message, char length){
jah128 0:d88fd55a27a6 70 char to_send [length+1];
jah128 0:d88fd55a27a6 71 to_send[0]=0x40;
jah128 0:d88fd55a27a6 72 for(int i=0;i<length;i++){
jah128 0:d88fd55a27a6 73 to_send[i+1] = message[i];
jah128 0:d88fd55a27a6 74 }
jah128 0:d88fd55a27a6 75 _i2c.write(LCD_ADDRESS,to_send,length+1);
jah128 0:d88fd55a27a6 76 }
jah128 0:d88fd55a27a6 77
jah128 0:d88fd55a27a6 78 void Display::set_position(char row, char column){
jah128 0:d88fd55a27a6 79 if(row < 2 && column < 16){
jah128 0:d88fd55a27a6 80 char pos = 128 +((row * 64)+column);
jah128 0:d88fd55a27a6 81 i2c_message(pos);
jah128 0:d88fd55a27a6 82 }
jah128 0:d88fd55a27a6 83 }
jah128 0:d88fd55a27a6 84
jah128 0:d88fd55a27a6 85 void Display::set_cursor(char enable){
jah128 0:d88fd55a27a6 86 cursor_on=enable;
jah128 0:d88fd55a27a6 87 _set_display();
jah128 0:d88fd55a27a6 88 }
jah128 0:d88fd55a27a6 89
jah128 0:d88fd55a27a6 90 void Display::set_blink(char enable){
jah128 0:d88fd55a27a6 91 blink_on=enable;
jah128 0:d88fd55a27a6 92 _set_display();
jah128 0:d88fd55a27a6 93 }
jah128 0:d88fd55a27a6 94
jah128 0:d88fd55a27a6 95 void Display::set_display(char enable){
jah128 0:d88fd55a27a6 96 display_on=enable;
jah128 0:d88fd55a27a6 97 _set_display();
jah128 0:d88fd55a27a6 98 }
jah128 0:d88fd55a27a6 99
jah128 0:d88fd55a27a6 100 void Display::clear_display(){
jah128 0:d88fd55a27a6 101 i2c_message(0x01);
jah128 0:d88fd55a27a6 102 }
jah128 0:d88fd55a27a6 103
jah128 0:d88fd55a27a6 104 void Display::home(){
jah128 0:d88fd55a27a6 105 i2c_message(0x02);
jah128 0:d88fd55a27a6 106 }
jah128 0:d88fd55a27a6 107
jah128 0:d88fd55a27a6 108
jah128 0:d88fd55a27a6 109 void Display::_set_display(){
jah128 0:d88fd55a27a6 110 char mode = 8;
jah128 0:d88fd55a27a6 111 if(display_on>0) mode += 4;
jah128 0:d88fd55a27a6 112 if(cursor_on>0) mode += 2;
jah128 0:d88fd55a27a6 113 if(blink_on>0) mode ++;
jah128 0:d88fd55a27a6 114 i2c_message(mode);
jah128 0:d88fd55a27a6 115 }
jah128 0:d88fd55a27a6 116
jah128 0:d88fd55a27a6 117
jah128 0:d88fd55a27a6 118 int Display::_putc (int c) {
jah128 0:d88fd55a27a6 119 putc(c);
jah128 0:d88fd55a27a6 120 return(c);
jah128 0:d88fd55a27a6 121 }
jah128 0:d88fd55a27a6 122
jah128 0:d88fd55a27a6 123 int Display::_getc (void) {
jah128 0:d88fd55a27a6 124 char r = 0;
jah128 0:d88fd55a27a6 125 return(r);
jah128 0:d88fd55a27a6 126 }
jah128 0:d88fd55a27a6 127
jah128 0:d88fd55a27a6 128
jah128 0:d88fd55a27a6 129 /* Permission is hereby granted, free of charge, to any person obtaining a copy
jah128 0:d88fd55a27a6 130 * of this software and associated documentation files (the "Software"), to deal
jah128 0:d88fd55a27a6 131 * in the Software without restriction, including without limitation the rights
jah128 0:d88fd55a27a6 132 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jah128 0:d88fd55a27a6 133 * copies of the Software, and to permit persons to whom the Software is
jah128 0:d88fd55a27a6 134 * furnished to do so, subject to the following conditions:
jah128 0:d88fd55a27a6 135 *
jah128 0:d88fd55a27a6 136 * The above copyright notice and this permission notice shall be included in
jah128 0:d88fd55a27a6 137 * all copies or substantial portions of the Software.
jah128 0:d88fd55a27a6 138 *
jah128 0:d88fd55a27a6 139 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jah128 0:d88fd55a27a6 140 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jah128 0:d88fd55a27a6 141 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jah128 0:d88fd55a27a6 142 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jah128 0:d88fd55a27a6 143 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jah128 0:d88fd55a27a6 144 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jah128 0:d88fd55a27a6 145 * THE SOFTWARE.
jah128 0:d88fd55a27a6 146 */