HW2 text entry device for idd 2015. Allows user to type with a knob and a push button.

Dependencies:   mbed

Committer:
franklu
Date:
Mon Sep 14 06:29:34 2015 +0000
Revision:
0:0028c9f455d1
added main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
franklu 0:0028c9f455d1 1 #include "mbed.h"
franklu 0:0028c9f455d1 2 #include "PinDetect.h"
franklu 0:0028c9f455d1 3 // Initialize a pins to perform analog input and digital output fucntions
franklu 0:0028c9f455d1 4 AnalogIn ain(A0);
franklu 0:0028c9f455d1 5 DigitalOut dout(D3);
franklu 0:0028c9f455d1 6 PinDetect pin(D2);
franklu 0:0028c9f455d1 7 char letter;
franklu 0:0028c9f455d1 8 char *lower_arr = " zyxwvutsrqponmlkjihgfedcba";
franklu 0:0028c9f455d1 9 char *upper_arr = " ZYXWVUTSRQPONMLKJIHGFEDCBA";
franklu 0:0028c9f455d1 10 char *arr = lower_arr;
franklu 0:0028c9f455d1 11 void enter(void)
franklu 0:0028c9f455d1 12 {
franklu 0:0028c9f455d1 13 printf("%c", letter);
franklu 0:0028c9f455d1 14 }
franklu 0:0028c9f455d1 15
franklu 0:0028c9f455d1 16 void capslock_on(void) {
franklu 0:0028c9f455d1 17 dout = !dout;
franklu 0:0028c9f455d1 18 }
franklu 0:0028c9f455d1 19
franklu 0:0028c9f455d1 20 int main(void)
franklu 0:0028c9f455d1 21 {
franklu 0:0028c9f455d1 22 dout = 0;
franklu 0:0028c9f455d1 23 pin.setSampleFrequency();
franklu 0:0028c9f455d1 24 pin.attach_asserted(&enter);
franklu 0:0028c9f455d1 25 pin.attach_deasserted_held(&capslock_on);
franklu 0:0028c9f455d1 26 printf("\r\n Input here: \r\n ");
franklu 0:0028c9f455d1 27 while (1) {
franklu 0:0028c9f455d1 28 if (dout){
franklu 0:0028c9f455d1 29 arr = upper_arr;
franklu 0:0028c9f455d1 30 } else {
franklu 0:0028c9f455d1 31 arr = lower_arr;
franklu 0:0028c9f455d1 32 }
franklu 0:0028c9f455d1 33 int input = (int)(ain.read()* 100.0f / 3.705f);
franklu 0:0028c9f455d1 34 letter = arr[input];
franklu 0:0028c9f455d1 35 printf("%c", letter);
franklu 0:0028c9f455d1 36 printf("\b");
franklu 0:0028c9f455d1 37 }
franklu 0:0028c9f455d1 38 }