Home › Forums › Elektronika / programavimas › E-Dviracio matuoklis
- This topic has 43 replies, 6 voices, and was last updated 11 years, 3 months ago by  agniusm. agniusm.
- 
		AuthorPosts
- 
		
			
				
2013/08/28 at 10:47 #5960 bondas83Participant bondas83ParticipantO kaip darote su mikrochemos(arduino) uzmaitinimu. nes pas mane pvz 72V. ar atskira maitinima naudojate, ar tik nuo kazkuriu celiu? 2014/06/26 at 21:55 #7595 agniusmParticipant agniusmParticipantBuvau palikes si reikala stalciuje. Isitraukiau vel, bandziau sujungti dvi programeles, bet niekaip nepavyko. Kodas herkonui rodyti greiti: #define reed A0//pin connected to read switch //storage variables int reedVal; long timer;// time between one full rotation (in ms) float mph; float radius = 13.5;// tire radius (in inches) float circumference; int maxReedCounter = 100;//min time (in ms) of one rotation (for debouncing) int reedCounter; void setup(){ reedCounter = maxReedCounter; circumference = 2*3.14*radius; pinMode(reed, INPUT); cli();//stop interrupts //set timer1 interrupt at 1kHz TCCR1A = 0;// set entire TCCR1A register to 0 TCCR1B = 0;// same for TCCR1B TCNT1 = 0; // set timer count for 1khz increments OCR1A = 1999;// = (1/1000) / ((1/(16*10^6))*8) - 1 // turn on CTC mode TCCR1B |= (1 << WGM12); // Set CS11 bit for 8 prescaler TCCR1B |= (1 << CS11); // enable timer compare interrupt TIMSK1 |= (1 << OCIE1A); sei();//allow interrupts //END TIMER SETUP Serial.begin(9600); } ISR(TIMER1_COMPA_vect) {//Interrupt at freq of 1kHz to measure reed switch reedVal = digitalRead(reed);//get val of A0 if (reedVal){//if reed switch is closed if (reedCounter == 0){//min time between pulses has passed mph = (56.8*float(circumference))/float(timer);//calculate miles per hour timer = 0;//reset timer reedCounter = maxReedCounter;//reset reedCounter } else{ if (reedCounter > 0){//don't let reedCounter go negative reedCounter -= 1;//decrement reedCounter } } } else{//if reed switch is open if (reedCounter > 0){//don't let reedCounter go negative reedCounter -= 1;//decrement reedCounter } } if (timer > 2000){ mph = 0;//if no new pulses from reed switch- tire is still, set mph to 0 } else{ timer += 1;//increment timer } } void displayMPH(){ Serial.println(mph); } void loop(){ //print mph once a second displayMPH(); delay(1000); }Reikia ideti i si kad rodytu greiti vietoj u8g.print(count);: #include “U8glib.h” U8GLIB_64128N u8g(13, 11, 10, 9, 8); //void draw(void) //lcd int count; //lcdLeftColumn function start void lcdTopColumn(void) { // u8g.drawFrame(7,0,114,9); u8g.drawBox(9,2,42,5); // u8g.setFont(u8g_font_6x10); u8g.setPrintPos(123, 8); u8g.print(“F”); u8g.setFont(u8g_font_5x8); u8g.setPrintPos(0, 17); u8g.print(“LIKO:”); u8g.setFont(u8g_font_6x10); u8g.setPrintPos(0, 25); u8g.print(“23 5KM”); u8g.setFont(u8g_font_6x10); u8g.setPrintPos(0, 8); u8g.print(“E”); } //lcdLeftColumn function end //lcdCenterColumn function start void lcdCenterColumn(void) { //u8g.drawFrame(40,12,80,40); //u8g.drawFrame(39,11,82,42); u8g.drawLine(40,15,40,48); u8g.drawLine(41,15,41,48); u8g.setFont(arcade); u8g.setFontPosCenter(); u8g.setPrintPos(44, 32); if (count <10) { u8g.print(“0″); u8g.print(count); } else { u8g.print(count); } } //lcdCenterColumn function end //lcdRightColumn function start void lcdBottomColumn(void) { // u8g.drawFrame(7,55,114,9); u8g.drawBox(58,57,10,5); // u8g.setFont(u8g_font_6x10); u8g.setPrintPos(0, 63); u8g.print(“+”); u8g.setFont(u8g_font_5x8); u8g.setPrintPos(0, 52); u8g.print(“GALIA:”); u8g.setFont(u8g_font_6x10); u8g.setPrintPos(0, 45); u8g.print(“0 75KW”); u8g.setFont(u8g_font_6x10); u8g.setPrintPos(123, 63); u8g.print(“-”); } //lcdRightColumn function end void setup(void) { count = 10; } void loop(void) { count = count + 1; if(count == 99){ count = 1; } //lcd u8g.firstPage(); do { //lcdLeftColumn start lcdTopColumn(); //lcdLeftColumn end //lcdCenterColumn start lcdCenterColumn(); //lcdCenterColumn end //lcdRightColumn start lcdBottomColumn(); //lcdRightColumn end } while( u8g.nextPage() ); //lcd //atvaizdavimo greitis ms delay(100); }- 
		This reply was modified 11 years, 4 months ago by  agniusm. agniusm.
 2014/07/23 at 08:40 #7909jonas Participantpabandyk taip, jei dar aktualu. #include <U8glib.h> 
 #define reed A0//pin connected to read switch
 U8GLIB_64128N u8g(13, 11, 10, 9, 8);
 //storage variables
 int reedVal;
 int count;
 long timer;// time between one full rotation (in ms)
 float mph;
 float radius = 13.5;// tire radius (in inches)
 float circumference;int maxReedCounter = 100;//min time (in ms) of one rotation (for debouncing) 
 int reedCounter;void setup(){ reedCounter = maxReedCounter; 
 circumference = 2*3.14*radius;
 pinMode(reed, INPUT);cli();//stop interrupts //set timer1 interrupt at 1kHz 
 TCCR1A = 0;// set entire TCCR1A register to 0
 TCCR1B = 0;// same for TCCR1B
 TCNT1 = 0;
 // set timer count for 1khz increments
 OCR1A = 1999;// = (1/1000) / ((1/(16*10^6))*8) – 1
 // turn on CTC mode
 TCCR1B |= (1 << WGM12);
 // Set CS11 bit for 8 prescaler
 TCCR1B |= (1 << CS11);
 // enable timer compare interrupt
 TIMSK1 |= (1 << OCIE1A);sei();//allow interrupts 
 //END TIMER SETUP
 count = 10;
 Serial.begin(9600);
 }ISR(TIMER1_COMPA_vect) {//Interrupt at freq of 1kHz to measure reed switch 
 reedVal = digitalRead(reed);//get val of A0
 if (reedVal){//if reed switch is closed
 if (reedCounter == 0){//min time between pulses has passed
 mph = (56.8*float(circumference))/float(timer);//calculate miles per hour
 timer = 0;//reset timer
 reedCounter = maxReedCounter;//reset reedCounter
 }
 else{
 if (reedCounter > 0){//don’t let reedCounter go negative
 reedCounter -= 1;//decrement reedCounter
 }
 }
 }
 else{//if reed switch is open
 if (reedCounter > 0){//don’t let reedCounter go negative
 reedCounter -= 1;//decrement reedCounter
 }
 }
 if (timer > 2000){
 mph = 0;//if no new pulses from reed switch- tire is still, set mph to 0
 }
 else{
 timer += 1;//increment timer
 }
 }void displayMPH(){ 
 Serial.println(mph);
 }void loop(){ 
 //print mph once a second
 displayMPH();
 count==mph;
 delay(1000);
 u8g.firstPage();
 do {draw(); } while( u8g.nextPage() ); 
 //lcd//atvaizdavimo greitis ms 
 delay(100);
 }void draw(void) 
 {
 u8g.drawFrame(7,0,114,9);
 u8g.drawBox(9,2,42,5);
 //u8g.setFont(u8g_font_6x10); 
 u8g.setPrintPos(123, 8);
 u8g.print(“F”);u8g.setFont(u8g_font_5x8); 
 u8g.setPrintPos(0, 17);
 u8g.print(“LIKO:”);
 u8g.setFont(u8g_font_6x10);
 u8g.setPrintPos(0, 25);
 u8g.print(“23 5KM”);u8g.setFont(u8g_font_6x10); 
 u8g.setPrintPos(0, 8);
 u8g.print(“E”);
 u8g.drawLine(40,15,40,48);
 u8g.drawLine(41,15,41,48);
 u8g.setFont(u8g_font_6x10); //pasikeisti fontus i arcade
 u8g.setFontPosCenter();
 u8g.setPrintPos(44, 32);
 if (count <10) {
 u8g.print(“0”);
 u8g.print(count);
 }
 else {
 u8g.print(count);
 }
 u8g.drawFrame(7,55,114,9);
 u8g.drawBox(58,57,10,5);
 //u8g.setFont(u8g_font_6x10); 
 u8g.setPrintPos(0, 63);
 u8g.print(“+”);u8g.setFont(u8g_font_5x8); 
 u8g.setPrintPos(0, 52);
 u8g.print(“GALIA:”);
 u8g.setFont(u8g_font_6x10);
 u8g.setPrintPos(0, 45);
 u8g.print(“0 75KW”);u8g.setFont(u8g_font_6x10); 
 u8g.setPrintPos(123, 63);
 u8g.print(“-“);
 }2014/07/23 at 22:38 #7910 agniusmParticipant agniusmParticipantDekui, be abejo aktualu. But gerai paroj 48H :) 
- 
		This reply was modified 11 years, 4 months ago by 
- 
		AuthorPosts
- You must be logged in to reply to this topic.
