The preloaded firmware shipped on the Medusa Icon.

Dependencies:   SoftwarePWM mbed

Committer:
Experiment626
Date:
Mon Sep 15 16:09:35 2014 +0000
Revision:
1:5d438f8b2afe
Parent:
0:034c0e606458
Added Apache 2 license text

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Experiment626 1:5d438f8b2afe 1 /*
Experiment626 1:5d438f8b2afe 2 ** This software can be freely used, even comercially, as highlighted in the license.
Experiment626 1:5d438f8b2afe 3 **
Experiment626 1:5d438f8b2afe 4 ** Copyright 2014 GHI Electronics, LLC
Experiment626 1:5d438f8b2afe 5 **
Experiment626 1:5d438f8b2afe 6 ** Licensed under the Apache License, Version 2.0 (the "License");
Experiment626 1:5d438f8b2afe 7 ** you may not use this file except in compliance with the License.
Experiment626 1:5d438f8b2afe 8 ** You may obtain a copy of the License at
Experiment626 1:5d438f8b2afe 9 **
Experiment626 1:5d438f8b2afe 10 ** http://www.apache.org/licenses/LICENSE-2.0
Experiment626 1:5d438f8b2afe 11 **
Experiment626 1:5d438f8b2afe 12 ** Unless required by applicable law or agreed to in writing, software
Experiment626 1:5d438f8b2afe 13 ** distributed under the License is distributed on an "AS IS" BASIS,
Experiment626 1:5d438f8b2afe 14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Experiment626 1:5d438f8b2afe 15 ** See the License for the specific language governing permissions and
Experiment626 1:5d438f8b2afe 16 ** limitations under the License.
Experiment626 1:5d438f8b2afe 17 **
Experiment626 1:5d438f8b2afe 18 **/
Experiment626 1:5d438f8b2afe 19
Experiment626 0:034c0e606458 20 #include "mbed.h"
Experiment626 0:034c0e606458 21 #include "SoftwarePWM.h"
Experiment626 0:034c0e606458 22
Experiment626 0:034c0e606458 23 SPI spi(P0_21, P0_22, P1_15); // mosi, miso, sclk
Experiment626 0:034c0e606458 24
Experiment626 0:034c0e606458 25 //enum EYE { LEFT = 0, RIGHT = 1 };
Experiment626 0:034c0e606458 26
Experiment626 0:034c0e606458 27 DigitalOut Latch(P0_4);
Experiment626 0:034c0e606458 28
Experiment626 0:034c0e606458 29 DigitalOut PWM1(P0_13);
Experiment626 0:034c0e606458 30 DigitalOut PWM2(P0_18);
Experiment626 0:034c0e606458 31 DigitalOut PWM3(P0_19);
Experiment626 0:034c0e606458 32 DigitalOut PWM4(P0_11);
Experiment626 0:034c0e606458 33 DigitalOut PWM5(P0_16);
Experiment626 0:034c0e606458 34 DigitalOut PWM6(P0_14);
Experiment626 0:034c0e606458 35
Experiment626 0:034c0e606458 36 //DigitalOut Eyes[] = {(P0_8), (P0_9)};// declare 2 LEDs of the eyes
Experiment626 0:034c0e606458 37 SoftwarePWM LeftEye(P0_8);
Experiment626 0:034c0e606458 38 SoftwarePWM RightEye(P0_9);
Experiment626 0:034c0e606458 39
Experiment626 0:034c0e606458 40 void WriteLED(uint64_t Shiftmap)
Experiment626 0:034c0e606458 41 {
Experiment626 0:034c0e606458 42 spi.write(Shiftmap >> 40);
Experiment626 0:034c0e606458 43 spi.write(Shiftmap >> 32);
Experiment626 0:034c0e606458 44 spi.write(Shiftmap >> 24);
Experiment626 0:034c0e606458 45 spi.write(Shiftmap >> 16);
Experiment626 0:034c0e606458 46 spi.write(Shiftmap >> 8);
Experiment626 0:034c0e606458 47 spi.write(Shiftmap);
Experiment626 0:034c0e606458 48
Experiment626 0:034c0e606458 49 Latch = true;
Experiment626 0:034c0e606458 50 Latch = false;
Experiment626 0:034c0e606458 51 }
Experiment626 0:034c0e606458 52
Experiment626 0:034c0e606458 53 //void BlinkEye(EYE eye, bool blink)
Experiment626 0:034c0e606458 54 //{
Experiment626 0:034c0e606458 55 // Eyes[eye] = blink;
Experiment626 0:034c0e606458 56 //}
Experiment626 0:034c0e606458 57
Experiment626 0:034c0e606458 58 void Initialize()
Experiment626 0:034c0e606458 59 {
Experiment626 0:034c0e606458 60 PWM1 = false;
Experiment626 0:034c0e606458 61 PWM2 = false;
Experiment626 0:034c0e606458 62 PWM3 = false;
Experiment626 0:034c0e606458 63 PWM4 = false;
Experiment626 0:034c0e606458 64 PWM5 = false;
Experiment626 0:034c0e606458 65 PWM6 = false;
Experiment626 0:034c0e606458 66
Experiment626 0:034c0e606458 67 spi.format(16,0);
Experiment626 0:034c0e606458 68 spi.frequency(10 * 1000 * 1000);
Experiment626 0:034c0e606458 69 }
Experiment626 0:034c0e606458 70
Experiment626 0:034c0e606458 71 int main()
Experiment626 0:034c0e606458 72 {
Experiment626 0:034c0e606458 73 Initialize();
Experiment626 0:034c0e606458 74
Experiment626 0:034c0e606458 75 uint64_t Shiftmap = 0x10101010101;
Experiment626 0:034c0e606458 76 int LED_counter = 1;
Experiment626 0:034c0e606458 77
Experiment626 0:034c0e606458 78 LeftEye.Enable(25, 1000);
Experiment626 0:034c0e606458 79 RightEye.Enable(25, 1000);
Experiment626 0:034c0e606458 80
Experiment626 0:034c0e606458 81 // bool isEyeOpen = false;
Experiment626 0:034c0e606458 82
Experiment626 0:034c0e606458 83 while ( true ) {
Experiment626 0:034c0e606458 84 WriteLED(Shiftmap);
Experiment626 0:034c0e606458 85 // isEyeOpen = !isEyeOpen;
Experiment626 0:034c0e606458 86 // BlinkEye(LEFT, isEyeOpen);
Experiment626 0:034c0e606458 87 // BlinkEye(RIGHT, !isEyeOpen);
Experiment626 0:034c0e606458 88
Experiment626 0:034c0e606458 89 if ( LED_counter++ < 8 ) {
Experiment626 0:034c0e606458 90 Shiftmap <<= 1;
Experiment626 0:034c0e606458 91 } else {
Experiment626 0:034c0e606458 92 Shiftmap = 0x10101010101;
Experiment626 0:034c0e606458 93 LED_counter = 1;
Experiment626 0:034c0e606458 94 }
Experiment626 0:034c0e606458 95
Experiment626 0:034c0e606458 96 wait(.075);
Experiment626 0:034c0e606458 97 }
Experiment626 0:034c0e606458 98
Experiment626 0:034c0e606458 99 }