Hi, so far I have both of the two different circuits and build but I require help in combining 3 vibration sensors and one 7 segment display.
Here are the two codes I have so far.
//Define the Pinout of 7 segment display
int a=7;
int b=6;
int c=5;
int d=11;
int e=10;
int f=8;
int g=9;
int dp=4;
//Display Number 1
void digital_1(void)
{
unsigned char j;
digitalWrite(c,LOW);//Set C Segment to low which lights this segment
digitalWrite(b,LOW);//Set B Segment to low which lights this segment
for(j=7;j<=11;j++)//Set the rest Segments to high which turn off this segment.
digitalWrite(j,HIGH);
digitalWrite(dp,HIGH);//Turn off DP segment (the little dot on the right down part)
}
//Display Number 2
void digital_2(void)
{
unsigned char j;
digitalWrite(b,LOW);
digitalWrite(a,LOW);
for(j=9;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
}
//Display Number 3
void digital_3(void)
{
unsigned char j;
digitalWrite(g,LOW);
digitalWrite(d,LOW);
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
}
//Display Number 4
void digital_4(void)
{
digitalWrite(c,LOW);
digitalWrite(b,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(dp,HIGH);
digitalWrite(a,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}
//Display Number 5
void digital_5(void)
{
unsigned char j;
for(j=7;j<=9;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
digitalWrite(e,HIGH);
}
//Display Number 6
void digital_6(void)
{
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
}
//Display Number 7
void digital_7(void)
{
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
for(j=8;j<=11;j++)
digitalWrite(j,HIGH);
}
//Display Number 8
void digital_8(void)
{
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
}
void setup()
{
int i;//Set Pin Mode as output
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);
}
void loop()
{
while(1)
{
digital_1();//Display Number 1
delay(500);//Delay 0.5 seconds
digital_2();
delay(500);
digital_3();
delay(500);
digital_4();
delay(500);
digital_5();
delay(500);
digital_6();
delay(500);
digital_7();
delay(500);
digital_8();
delay(500);
}
}
And then!!!
// these constants won't change:
const int ledPin = 13; // LED connected to digital pin 13
const int knockSensor = A0;
const int knockSensor1 = A1;
const int knockSensor2 = A2;
const int threshold = 1; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int sensorReading1 = 0;
int sensorReading2 = 0;
void setup() {
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
sensorReading1 = analogRead(knockSensor1);
sensorReading2 = analogRead(knockSensor2);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// send the string "Knock!" back to the computer, followed by newline
Serial.println("Mike!");
}
if (sensorReading1 >= threshold) {
// send the string "Knock!" back to the computer, followed by newline
Serial.println("Mike!");
}
if (sensorReading2 >= threshold) {
// send the string "Knock!" back to the computer, followed by newline
Serial.println("Mike!");
}
delay(500); // delay to avoid overloading the serial port buffer
}
Please help me!!! I need help