This example positions a lit LED in the I2C LED array using the rotary encoder

Dependencies:   mbed

Committer:
chris
Date:
Tue Mar 02 08:27:23 2010 +0000
Revision:
0:498b9b4a7bb9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:498b9b4a7bb9 1 #include "mbed.h"
chris 0:498b9b4a7bb9 2 #include "RotaryEncode.h"
chris 0:498b9b4a7bb9 3 #include "PCA9532.h"
chris 0:498b9b4a7bb9 4
chris 0:498b9b4a7bb9 5 RotaryEncode RE(p16,p17);
chris 0:498b9b4a7bb9 6 PCA9532 leds (p28,p27,0xc0);
chris 0:498b9b4a7bb9 7
chris 0:498b9b4a7bb9 8 int main() {
chris 0:498b9b4a7bb9 9
chris 0:498b9b4a7bb9 10 int position = 0;
chris 0:498b9b4a7bb9 11
chris 0:498b9b4a7bb9 12 while(1) {
chris 0:498b9b4a7bb9 13
chris 0:498b9b4a7bb9 14 int offset = RE.read();
chris 0:498b9b4a7bb9 15
chris 0:498b9b4a7bb9 16 if ((offset > 0) && (position < 15)) {
chris 0:498b9b4a7bb9 17 position++;
chris 0:498b9b4a7bb9 18 }
chris 0:498b9b4a7bb9 19 else if ((offset < 0) && (position > 0)) {
chris 0:498b9b4a7bb9 20 position--;
chris 0:498b9b4a7bb9 21 }
chris 0:498b9b4a7bb9 22
chris 0:498b9b4a7bb9 23 leds.write(0x1 << position);
chris 0:498b9b4a7bb9 24 wait (0.2);
chris 0:498b9b4a7bb9 25
chris 0:498b9b4a7bb9 26 }
chris 0:498b9b4a7bb9 27 }
chris 0:498b9b4a7bb9 28
chris 0:498b9b4a7bb9 29