piggi board test program

Dependencies:   mbed

Committer:
zatakon
Date:
Thu Sep 10 07:42:34 2015 +0000
Revision:
0:b6ef5f2b5390
piggi board test program;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zatakon 0:b6ef5f2b5390 1 #include "mbed.h"
zatakon 0:b6ef5f2b5390 2
zatakon 0:b6ef5f2b5390 3 DigitalOut led1(LED1);
zatakon 0:b6ef5f2b5390 4 DigitalOut led2(LED2);
zatakon 0:b6ef5f2b5390 5 DigitalOut led3(LED3);
zatakon 0:b6ef5f2b5390 6 DigitalOut led4(LED4);
zatakon 0:b6ef5f2b5390 7
zatakon 0:b6ef5f2b5390 8 AnalogIn controll(p15);
zatakon 0:b6ef5f2b5390 9 PwmOut motor(p26);
zatakon 0:b6ef5f2b5390 10 DigitalOut motor_direction(p25);
zatakon 0:b6ef5f2b5390 11
zatakon 0:b6ef5f2b5390 12 void init() {
zatakon 0:b6ef5f2b5390 13 // inicializacni sekvence
zatakon 0:b6ef5f2b5390 14 int sekvenc[9][4] = {{0,0,0,0},{0,0,0,1},{0,0,1,0},{0,1,0,0},{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1},{0,0,0,0}};
zatakon 0:b6ef5f2b5390 15 for( int i = 0; i < 9; i++ ) {
zatakon 0:b6ef5f2b5390 16 led1 = sekvenc[i][0];
zatakon 0:b6ef5f2b5390 17 led2 = sekvenc[i][1];
zatakon 0:b6ef5f2b5390 18 led3 = sekvenc[i][2];
zatakon 0:b6ef5f2b5390 19 led4 = sekvenc[i][3];
zatakon 0:b6ef5f2b5390 20 wait(0.1);
zatakon 0:b6ef5f2b5390 21 }
zatakon 0:b6ef5f2b5390 22 }
zatakon 0:b6ef5f2b5390 23
zatakon 0:b6ef5f2b5390 24 int main() {
zatakon 0:b6ef5f2b5390 25 init();
zatakon 0:b6ef5f2b5390 26 motor.period(1/1000); // 40 kH max
zatakon 0:b6ef5f2b5390 27
zatakon 0:b6ef5f2b5390 28 while(1) {
zatakon 0:b6ef5f2b5390 29 // kontrola pomoci led
zatakon 0:b6ef5f2b5390 30 led1 = (controll > 0.15f) ? 1 : 0;
zatakon 0:b6ef5f2b5390 31 led2 = (controll > 0.30f) ? 1 : 0;
zatakon 0:b6ef5f2b5390 32 led3 = (controll > 0.45f) ? 1 : 0;
zatakon 0:b6ef5f2b5390 33 led4 = (controll > 0.60f) ? 1 : 0;
zatakon 0:b6ef5f2b5390 34
zatakon 0:b6ef5f2b5390 35 // ovladani motor
zatakon 0:b6ef5f2b5390 36 motor.pulsewidth((1/1000) * (2 * controll));
zatakon 0:b6ef5f2b5390 37 motor_direction = ( controll > 0.4 ) ? 1 : 0;
zatakon 0:b6ef5f2b5390 38
zatakon 0:b6ef5f2b5390 39
zatakon 0:b6ef5f2b5390 40 wait_ms(50);
zatakon 0:b6ef5f2b5390 41 }
zatakon 0:b6ef5f2b5390 42 }