aarg:
Please post code that actually compiles without errors. Also please use ctrl-T to format your code, before posting it using code tags as requested in the sticky posts at the top of the forum, like this:
#define myOutputPin 13
int x;
int toggle = 0;
void setup() {
// put your setup code here, to run once:
pinMode(myOutputPin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(myOutputPin,HIGH);
TODELAY();
digitalWrite(myOutputPin,LOW);
TODELAY();
}
}
void TODELAY(){
TCCR0A=0;
TCCR0B=0;
TCNT0=0;
OCR0A=x;
TCCR0A |=(1<<COM0A0)|(1<<WGM01);
TCCR0B |=(1<<CS02);
}
ok so here is the full code
#include "LiquidCrystal.h" //lcd libary
#define myOutputPin 13
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); //LCD object Parameters: (rs, enable, d4, d5, d6, d7)
int ledPins[] = {0,1,2,3,4,5,6,7};
int i;
const int trigPin = 12; //trig pin connection
const int echoPin = 11; //echopin connection
long duration;
int distanceCm;
float liquid;
int x;
int toggle = 0;
void setup() { // setup perameter
pinMode(8, OUTPUT);
lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.setCursor(0,0);
lcd.print(" Distance ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
delay(2000);
lcd.clear();
for(int i = 0; i < 8; i++){
pinMode(ledPins[i],OUTPUT);
}
pinMode(myOutputPin,OUTPUT);
}
void loop() { // loop of flow program
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
lcd.setCursor(0,0);
lcd.print("Distance Measur.");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance:");
lcd.print(distanceCm);
lcd.print(" Cm ");
delay(10);
x=map(distanceCm,3,422,0,255);
showBinNumber(x);
delay(10);
digitalWrite(myOutputPin,HIGH);
TODELAY();
digitalWrite(myOutputPin,LOW);
TODELAY();
}
void showBinNumber(int num) {
for (int i=0; i<8; i++) {
if (num%2)
digitalWrite(ledPins[i], LOW);
else
digitalWrite(ledPins[i], HIGH);
num/=2;
}
}
void TODELAY(){
TCCR0A=0;
TCCR0B=0;
TCNT0=0;
OCR0A=x;
TCCR0A |=(1<<COM0A0)|(1<<WGM01);
TCCR0B |=(1<<CS02);
}