Components and supplies
Arduino UNO
Project description
Code
Long Way Home
arduino
That is the code for the center box
1/* Auswertung von Winkelencoder mit Lochscheibe 2/* und zwei Reflex-Lichtschranken 3/* 4 * Lab3 09/2012 Nawrath 5 * Kunsthochschule fuer Medien Koeln 6 * Academy of Media Arts Cologne 7 * h ttp://interface.khm.de 8 9 thanks to adafruit, ideas have be taken from the 10 Arduino library for the LPD8806-based strip. 11 12 This program is free software: you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation, either version 3 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program. If not, see <http://www.gnu.org/licenses/>. 24 */ 25 26 27 28 29#include <AFMotor.h> 30 31AF_DCMotor motor(1, MOTOR12_64KHZ); 32 33 34int pinIRGnd=19; 35int pinIRVcc=18; 36int pinIRb=17; 37int pinIRa=16; 38 39int pinLed= 13; 40 41 42#define debug 0 43 44 45 46/* SETUP */ 47void setup () { 48 Serial.begin(115200); 49 pinMode(pinLed, OUTPUT); 50 51 52 pinMode(pinIRGnd, OUTPUT); 53 pinMode(pinIRVcc, OUTPUT); 54 pinMode(pinIRa, INPUT); 55 pinMode(pinIRb, INPUT); 56 digitalWrite(pinIRVcc,1); 57 58} 59 60/* MAIN LOOP */ 61//**************************************************************************** 62void loop(){ 63 64 int SpeedPoti = analogRead(A0); 65 motor.setSpeed(SpeedPoti*0.249); 66 67 if (SpeedPoti>10) 68 { 69 motor.run(FORWARD); 70 } 71 else 72 { 73 motor.run(RELEASE); 74 } 75 76 77 int ww=getIrSensors(); 78 79} 80//**************************************************************************** 81int getIrSensors() { 82 83 int teilungen=24; // Anzahl der Sektoren auf der Scheibe 84 int nMax= 1; // max Umdregungen 85 86 int teilgrad=360/teilungen; 87 88 static int iraa,irba,winkel; 89 static long milA,milAa,milAaT; 90 static int f_init=1; 91 static int tSektor,tSektorTeil; 92 static int wTeilSektor; 93 static int cntSektor,cnt360; 94 95 96 97 int ira= digitalRead(pinIRa); // Sektor Spur 98 int irb= digitalRead(pinIRb); // 360 Spur 99 digitalWrite(pinLed,ira); 100 101 102 milA=millis(); 103 104 if (milA >= milAaT + tSektorTeil){ // Winelausgabe berecnet aus Sektore x Umdehungen + extrapoliertem Winke 105 wTeilSektor++; 106 winkel=wTeilSektor+cntSektor*360/teilungen+cnt360*360; 107 108 milAaT=milA; 109 110 Serial.println(winkel ); 111 112 } 113 114 115 if (ira == 1 && iraa ==0 ) { // Sektor Spur 116#if debug 117 Serial.print("*** Sektor "); 118#endif 119 // if (!f_360 ) 120 cntSektor++; 121 // f_360=0; 122 123 tSektor= milA-milAa; 124 tSektorTeil= tSektor/teilgrad; 125 milAa=milA; 126 wTeilSektor=0; 127 winkel=wTeilSektor+cntSektor*360/teilungen+cnt360*360; 128#if debug 129 Serial.print("sec:"); 130 Serial.print(cntSektor); 131 132 Serial.print(" 360:"); 133 Serial.print(cnt360); 134 Serial.print(" tS:"); 135 Serial.print(tSektor); 136 Serial.print(" tW:"); 137 Serial.print(tSektorTeil); 138 Serial.print(" W:"); 139 Serial.print(winkel); 140 Serial.println(""); 141#endif 142 143 } 144 145 146 if (irb == 1 && irba == 0) { // 360 Spur 147#if debug 148 Serial.print("### 360 "); 149#endif 150 while ( digitalRead(pinIRa)==0) { 151 delay(1); 152 153 } 154 wTeilSektor=0; 155 cnt360++; 156 cntSektor=0; 157 ira=1; 158 if (f_init) { 159 cnt360=0; 160 f_init=0; 161 } 162 if (cnt360 >= nMax ) cnt360=0; 163 } 164 165 166 iraa=ira; 167 irba=irb; 168 169 return(winkel); 170 171} 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
Downloadable files
No schematics.
Sorry, I don't have any schematics.
No schematics.
No schematics.
Sorry, I don't have any schematics.
No schematics.
Comments
Only logged in users can leave comments
kabelton
0 Followers
•0 Projects
Table of contents
Intro
6
0