Вы находитесь на странице: 1из 27

. ..

++

:
-232

:
..

________________2017.
_________________


2017
1.
: 3 ,
.
:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main()
{
wiringPiSetupPhys ();
pinMode (31, OUTPUT);
delay(3000);
digitalWrite(31, HIGH);
delay(1000);
digitalWrite(31, LOW);
}
2.
: 3 , 10 .

:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main ()
{
int i;
wiringPiSetupPhys () ;
pinMode (31, OUTPUT);
delay(3000);
for(i=0;i<10;i++)
{
digitalWrite(31,i%2);
delay(500);
}
}

/ ,
..
1 i int
3.
:

:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main ()
{
int i;
wiringPiSetupPhys () ;
pinMode (31, OUTPUT);
pinMode (33, OUTPUT);
delay(3000);
for( ; ; )
{
digitalWrite(31, i%2);
digitalWrite(33, (int) ! (i%2));
delay(500);
}
}
4.
: , Push

:
#include <stdio.h>
#include <wiringPi.h>
int main ()
{
wiringPiSetupPhys () ;
pinMode (16, INPUT);
while(1)
if(!digitalRead(16)) printf("Push ");
}
5.
: ,

:
#include <stdio.h>
#include <wiringPi.h>
int main ()
{
wiringPiSetupPhys ();
pinMode (18, INPUT);
pinMode (33, OUTPUT);
while (1)
if(!digitalRead(18))
digitalWrite(33, HIGH);
else
digitalWrite(33, LOW);
}

pinMode
digitalRead(18) (18,INPUT)
pinMode
(33,OUTPUT)

+ (1) -

+ - -

(33, (33,
HIGH) LOW)


6.
: 1 . 2

:
#include <stdio.h>
#include <wiringPi.h>
int main ()
{
wiringPiSetupPhys () ;
pinMode (18, INPUT);
pinMode (19, INPUT);
pinMode (31, OUTPUT);
while(1)
{
if(!digitalRead(19)) digitalWrite(31,HIGH);
if(!digitalRead(18)) digitalWrite(31,LOW);
}
}

pinMode (19, INPUT);


digitalRead(19) pinMode (31, OUTPUT);
pinMode (18, INPUT);

(1) -

+ -

(33,
HIGH)

digitalRead(19)
+ -

(33,
LOW)


7. ,
. .
:

:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wiringPi.h>
#include <unistd.h>
#define PATH "/sys/bus/w1/devices/28-0416589843ff/w1_slave"
int main()
{
int atoi(const char* str);
FILE *fil;
char str[50];
int c;
float g;
float t=0;
while(1) {
if((fil=fopen(PATH,"r"))==NULL) return 1;
do
fscanf(fil,"%s",str);
while(str[0]!='t');
fclose(fil);
for (int i = 2; i <50; i++)
str[i-2] = str[i];
c=atoi(str);
g=float(c);
g/=1000;
t=g-t;
printf("t1=%f\n",g);
printf("trazn=%f\n",t);
delay(1000);
}
}
/ ,
..
1 i int
2 str char

3 g float

4 float

digitalRead(19) t=0

(1)

+ -

(33,
HIGH)

digitalRead(19)
+ -

(33,
LOW)


8.
: 1,
2
:
#include <stdio.h>
#include <wiringPi.h>
static int global;
static int c;
void myInterrupt0 (void) { ++global; }
void myInterrupt1 (void) { ++c; }
int main (void)
{
int gotOne, myCounter, b, d;
global=myCounter=0;
c=d=0;
wiringPiSetupPhys() ;
pinMode (31, OUTPUT);
pinMode (33, OUTPUT);
wiringPiISR (21, INT_EDGE_FALLING, &myInterrupt0);
wiringPiISR (22, INT_EDGE_FALLING, &myInterrupt1);
for (;;)
{
gotOne = 0 ;
b=0;
printf ("Waiting ... ") ; fflush (stdout) ;
for (;;)
{
if (global != myCounter)
{
printf ("Audio counter:%5d\n",global);
digitalWrite(31, HIGH);
delay(1000);
digitalWrite(31, LOW);
myCounter = global;
++gotOne ;
}
if (d != c)
{
printf ("svet counter: %5d\n",c) ;
d=c;
++b;
digitalWrite(33, HIGH);
delay(1000);
digitalWrite(33, LOW);
}
if (gotOne != 0) break ;
if (b!=0) break;
}
}
}
/ ,
..
1 global int
2 c int
3 gotOne int

4 myCounter int
5 b int

6 d int

global++

global++


global=myCounter=0;
c=d=0;

pinMode(31, OUTPUT);
pinMode(33, OUTPUT);

(;;)

gotOne=0;
b=0;

Waiting...

#9 #8 #1
#5
#5
#9 #8 #1

global!=myCounter
+ -
Audio counter:
global

(31,HIGH)
(31,LOW)

myCounter=global

++gotOne

+ -
d!=c
Svet counter:
c

(33,HIGH)
(33,LOW)

d=c

#6 #7 #2 #3 #4
#3 #4
#6 #7 #2

++b

gotOne!=0
+ -

+
b!=0
9.
:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main ()
{
int a[]={31,33,35,32};
int k,b;
wiringPiSetupPhys () ;
pinMode (31, OUTPUT);
pinMode (33, OUTPUT);
pinMode (35, OUTPUT);
pinMode (32, OUTPUT);
delay(3000);
for( ; ; )
{
for (k=0,b=1;k<5;k++,b++)
{
if(k==4)
digitalWrite(a[k-1], LOW);
if(b==4)
b=0;
else
digitalWrite(a[b+1], LOW);
digitalWrite(a[k], HIGH);
digitalWrite(a[b], HIGH);
digitalWrite(a[k-1], LOW);
delay(500);
}
}
}

/ ,
..
1 a[] int pin
2 k int
3 b int
10.
:

:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main ()
{
wiringPiSetupPhys () ;
pinMode (40, OUTPUT);
pinMode (38, OUTPUT);
pinMode (36, OUTPUT);
pinMode (37, OUTPUT);
delay(3000);
for( ; ; )
{
digitalWrite(40, 1);
delay(500);
digitalWrite(40, 0);
digitalWrite(38, 1);
delay(500);
digitalWrite(38, 0);
digitalWrite(36, 1);
delay(500);
digitalWrite(36, 0);
digitalWrite(37, 1);
delay(500);
digitalWrite(37, 0);
delay(500);
}
}
11. -
: - 180

:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main()
{
wiringPiSetupPhys () ;
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
delay(3000);
for( ; ; )
{
system("echo p1-12=250 > /dev/servoblaster");
delay(600);
system("echo p1-12=50 > /dev/servoblaster");
delay(1500);
}
}
12.
: -
.
:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main()
{
wiringPiSetupPhys () ;
pinMode(12, OUTPUT);
pinMode (18, INPUT);
delay(3000);
for( ; ; )
{
system("echo p1-12=250 > /dev/servoblaster");
delay(600);
system("echo p1-12=50 > /dev/servoblaster");
delay(1500);
if (!digitalRead(18)) break;
}
}
13.
: 1,
2

:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#define PATH "/dev/servoblaster"
int main ()
{
wiringPiSetupPhys ();
pinMode(12, OUTPUT);
pinMode (18, INPUT);
pinMode (19, INPUT);
for( ; ; )
{
if(!digitalRead(19))
{
system("echo p1-12=250 >
/dev/servoblaster");
}
if(!digitalRead(18))
{
system("echo p1-12=50 >
/dev/servoblaster");
}
}
}
14.
: ASCII . 1,
, 0 .
, .

:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include "GitHublcd.h"
#include <string.h>
#include <math.h>
static int f;
static int globalCounter;
int a[8];
int i=0;
int c=0;
int d,t,g;
void myInterrupt0 (void) { ++globalCounter; }
void myInterrupt1 (void) { ++f; }
void vvod()
{
lcdcls();
lcdseek (LINE1);
print_str ("Vvedite chislo");
f=g=0;
wiringPiISR (19, INT_EDGE_FALLING, &myInterrupt0) ;
wiringPiISR (18, INT_EDGE_FALLING, &myInterrupt1) ;
for (;;)
{
if(!digitalRead(19))
{
digitalWrite(31,HIGH);
delay(100);
digitalWrite(31, LOW);
a[i]=1;
i++;
delay(100);
}
if(!digitalRead(18))
{
digitalWrite(33,HIGH);
delay(100);
digitalWrite(33, LOW);
a[i]=0;
i++;
delay(100);
}
if (i>=8) break ;
}
}

void perevorot()
{
for (i=0;i<8/2;i++)
{
t=a[i];
a[i]=a[8-i-1];
a[8-i-1]=t;
}
}
void vich()
{
for(i=0;i<8;i++)
{
d=pow(2,i);
c=c+(a[i]*d);
}
}
void vivod()
{
lcdcls();
lcdseek (LINE1);
print_int (c);
lcdseek (LINE2);
print_char (c);
}
int main()
{
lcd_init ();
wiringPiSetupPhys ();
pinMode (19, INPUT);
pinMode (18, INPUT);
pinMode (16, INPUT);
pinMode (31, OUTPUT);
pinMode (33, OUTPUT);
vvod();
perevorot();
vich();
vivod();
}