Saturday, August 7, 2010

Arduino based Oscilloscope + LED matrix display














code:
**************************************************************************
int counter=0;
int sv;
int mem[200];
int t=0;
int sv2=0;
int ss=0;
int d=0;
int de=0;
int mode;
int sv3=0;
int c=0;
void setup()
{
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(0,OUTPUT);
mode=analogRead(4);
mode=map(mode,0,1024,0,3);

de=analogRead(3);
de=map(de,1,1024,0,10);
//de=map(de,1,1024,-1,2);
//de=pow(10,de);
delay(100);
if (mode==1){
while (t<=200)
{
sv=analogRead(0);
delay(de);
sv=map(sv,0,1024,0,7);
mem[t]=sv;
t=t+1;
}
}
///////////////////////
if (mode==0){
while (t<=200)
{
sv=analogRead(0);
delay(de);
sv=map(sv,0,1024,0,20);
mem[t]=sv;
t=t+1;
}
}
}
void loop()
{
if (d==10)
{
d=0;
sv2=analogRead(1);
sv3=analogRead(2);
sv3=map(sv3,0,1024,0,20);
sv2=map(sv2,0,1024,0,200);
//////////// refreshing the seting/////
de=analogRead(3);
mode=analogRead(4);
mode=map(mode,0,1024,0,3);
de=map(de,1,1024,0,10);
//de=map(de,1,1024,-1,2);
// de=pow(10,de);
///////////////////////////
}
if (mode==2)
{
if (c==10)
{
sampling();
c=0;
}
}
c=c+1;
d=d+1;
desplay();
}
void desplay(){
t=sv2;
ss=sv2+6;
delay(1);
while (t<=ss)
{
delay(0);
sv=mem[t];
writel();
t=t+1;
delay(1);
}
}
void sampling(){
t=0;
if (mode==1){
while (t<=200)
{
sv=analogRead(0);
delay(de);
sv=map(sv,0,1024,0,7);
mem[t]=sv;
t=t+1;
}
}
///////////////////////
if (mode==2){
while (t<=200)
{
sv=analogRead(0);
delay(de);
sv=map(sv,0,1024,0,7);
mem[t]=sv;
t=t+1;
}
}
///////////////////////
if (mode==0){
while (t<=200)
{
sv=analogRead(0);
delay(de);
sv=map(sv,0,1024,0,20);
mem[t]=sv;
t=t+1;
}
}
////////////////////////
}
void writel(){
digitalWrite(0,LOW);
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
if (mode==0)
{
sv=sv3-sv;
}
if (sv==0)
{
digitalWrite(6,HIGH);
}
if (sv==1)
{
digitalWrite(5,HIGH);
}
if (sv==2)
{
digitalWrite(4,HIGH);
}
if (sv==3)
{
digitalWrite(3,HIGH);
}
if (sv==4)
{
digitalWrite(2,HIGH) ;
}
if (sv==5)
{
digitalWrite(1,HIGH);
}
if (sv==6)
{
digitalWrite(0,HIGH) ;
}
sr();
}
void sr()
{
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
if (counter==0)
{
digitalWrite(7,LOW);
}
if (counter==1)
{
digitalWrite(8,LOW);
}
if (counter==2)
{
digitalWrite(9,LOW);
}
if (counter==3)
{
digitalWrite(10,LOW);
}
if (counter==4)
{
digitalWrite(11,LOW);
}
if (counter==5)
{
digitalWrite(12,LOW);
}
if (counter==6)
{
digitalWrite(13,LOW);
counter=-1;
}
counter=counter+1;
}
****************************************
NOTE:
By turning the PR4 the voltage at analog pin # 4 changes and it causes the mode of the oscilloscope to change.
here are different modes :
Mode # 1 : 0-1.5V ===> Capturing one set of samples and showing them in a wide vertical range ( in this mode, the vertical shift feature is enable )
Mode # 2: 1.5v-3.3v ===> Capturing one set of samples and showing them on display with fixed rang ( the vertical shift is disable)
Mode #3 : 3.3v-5v ===> Capturing a set of samples every 100 ms and showing them on screen with fixed range.

To capture new samples in the modes # 1 and 2 the Arduino has to be restarted.

At the end, the switches number 1 and 2 must be disconnect while Arduino is receiving data from computer. the pins number 0 and 1 are used as TX and RX , so connecting them to LEDs interrupts the communication between PC and Arduino

The DC offset Switch is used to disconnect the PR5 from input line when a normal input is needed ( By connecting offset switch , the input range is changed from 0-5V to -5_+5 which can be adjusted with PR5) . Be aware that offset mode only work when in put is an AC signal.



Check my video in YouTube :




No comments:

Post a Comment