Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BufferedSerial
Fork of FRDM_wahadlo_torsyjne by
Revision 3:2ba53b9a499a, committed 2014-06-10
- Comitter:
- Pawel_13
- Date:
- Tue Jun 10 09:46:18 2014 +0000
- Parent:
- 2:78a032749524
- Child:
- 4:16316fb634a4
- Commit message:
- DIRECTION
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jun 10 08:22:02 2014 +0000
+++ b/main.cpp Tue Jun 10 09:46:18 2014 +0000
@@ -6,10 +6,15 @@
DigitalOut direction(PTC7); //wyjście PTC7 jako kierunek obrotów
DigitalOut myled(LED_GREEN); //dioda zielona jako wizualizacja PWM
AnalogIn ain0(PTB0); //deklaracja wejść analogowych
-AnalogIn ain1(PTB1);
+//AnalogIn ain1(PTB1);
+
PwmOut motor(PTA5); //sygnał PWM do sterowania sterownikiem silnika krokowego
Serial pc(USBTX,USBRX); // komunikacja z PC
+float get_voltage_in(AnalogIn analog_in) {
+ return analog_in.read() * 2.9035; // kalibracja -0.01% wartości odczytanej
+}
+
int main() {
motor.period_us(motor_period);
@@ -18,14 +23,23 @@
if (RotTime>=motor_period){
}
+ int i_start = 0;
+ int SWITCH_DIR = 120;
- while (true) {
- wait(0.5);
- pc.printf("a0:%d\n",ain0.read_u16());
- pc.printf("a1:%d\n",ain1.read_u16());
-
- myled = !myled;
- direction= !direction;
+ while (true) {
+ wait_ms(start);
+ pc.printf("%.4f\n", get_voltage_in(ain0));
+
+// pc.printf("a1:%d\n",ain1.read_u16());
+ i_start++;
+ if (i_start == SWITCH_DIR) {
+ myled = !myled;
+ direction= !direction;
+ if (SWITCH_DIR == 120) SWIYCH_DIR = 240
+ i_start = 0
+ }
+
+
//zmiana czestotliwosci ifami tutaj
