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.
Diff: suncokret.h
- Revision:
- 3:bd92b23688ae
- Child:
- 4:e360384c268b
diff -r b1ba1e6b10be -r bd92b23688ae suncokret.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/suncokret.h Fri Feb 07 19:27:04 2020 +0000
@@ -0,0 +1,124 @@
+#include "mbed.h"
+#define DULJINA_PULSA1 0.001
+#define STANI 0
+#define CW 0.0035
+#define CCW 0.006
+Serial pc(SERIAL_TX, SERIAL_RX);
+AnalogIn in0(A0);
+AnalogIn in1(A1);
+AnalogIn in2(A2);
+AnalogIn in3(A3);
+DigitalOut ledica(D4);
+
+Timeout cekanje;
+
+PwmOut pwmd(D5);
+PwmOut pwmg(D6);
+
+float fotootp1=0, fotootp2=0, fotootp3=0, fotootp4=0;
+//float gore, dolje, lijevo, desno, sum;
+float ref, refV, refM;
+
+int pozicija;
+
+/*
+void sumiranje(){
+ gore = fotootp1 + fotootp2;
+ dolje = fotootp3 + fotootp4;
+ lijevo = fotootp1 + fotootp3;
+ desno = fotootp2 + fotootp4;
+
+ sum = fotootp1+fotootp2+fotootp3+fotootp4;
+ }
+*/
+void ocitanje(){
+ /* fotootp1 = in0.read();
+ fotootp2 = in2.read();
+ fotootp3 = in2.read();
+ fotootp4 = in3.read(); */
+
+ fotootp1 = in0.read();
+ printf("\n\r%f", fotootp1);
+ fotootp2 = in1.read();
+ printf("\n\r%f", fotootp2);
+ fotootp3 = in2.read();
+ printf("\n\r%f", fotootp3);
+ fotootp4 = in3.read();
+ printf("\n\r%f\n\n", fotootp4);
+ wait(2);
+
+ //sumiranje();
+
+ }
+
+
+void gore(){
+ pwmg.period_ms(20);
+ while(1){
+ pwmg.pulsewidth(CCW);
+ }
+ }
+
+void desno(){
+ pwmd.period_ms(20);
+ while(1){
+ pwmd.pulsewidth(CCW);
+ }
+ }
+
+void dolje(){
+ pwmg.period_ms(20);
+ while(1){
+ pwmg.pulsewidth(CW);
+ }
+ }
+
+void lijevo(){
+ pwmd.period_ms(20);
+ while(1){
+ pwmd.pulsewidth(CW);
+ }
+ }
+
+
+void pozicioniranje(){
+ switch(pozicija){
+ case 1:
+ cekanje.attach(&gore, 0.1);
+ break;
+ case 2:
+ cekanje.attach(&desno, 0.1);
+ break;
+ case 3:
+ cekanje.attach(&dolje, 0.1);
+ break;
+ case 4:
+ cekanje.attach(&lijevo, 0.1);
+ break;
+ default:
+ pc.printf("pogresna informacija");
+ break;
+ }
+ }
+
+void logika(){
+
+ }
+
+void trazenje(){
+ pwmd.period_ms(20);
+ while(1){
+ //ocitanje();
+ //pozicioniranje();
+ //logika();
+ refV = ref + 0.2;
+ refM = ref - 0.2;
+ //if(sum >= refV & sum <= refV){
+ //pwmd.pulsewidth(0.020);
+ pwmd=0.9;
+ ledica=1;
+ pc.printf("AAAAAAAAAAA");
+ // }
+ }
+ }
+