O‘ZBЕKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR VAZIRLIGI
MUHAMMAD AL – XORAZMIY NOMIDAGI TOSHKЕNT AXBOROT TЕXNOLOGIYALARI UNIVЕRSITЕTI NURAFSHON FILIALI
“Kompyuter injiniringi” fakulteti
210-21 KIo` guruhi talabasi
Begmatov Izzat ning
«O`rnatilgan tizimlar» fanidan bajargan
Amaliy ishi
Nurafshon-2024
2-amaliy topshiriq.
Topshiriqlar:
1. Potensiometrdan foydalangan holda arduino orqali yorug‘lik diodining yorug‘lik darajasini o‘zgartirish va ularning sonini o‘zgartirish.
2. RGB-yorug‘lik diodi. Impuls kengligining modulyatsiyasi.
3. Bir va to‘rt razryadli yetti segmetli indikatorlardan foydalanish va raqamlarni indikatorga chiqarish.
4. Tinkercad platformasidan foydalangan holda topshiriqlarni simulatsiyasi (prototip)ni ishlab chiqish.
5. Bajarilgan amaliy ishning dasturiy ta’minotini ishlab chiqish va topshiriqni o‘z vaqtida himoya qilish.
//Constant variables
const int brightnessPin = 2; //The number of brightness button pin
const int rgbPin = 4; //The number of rgb button pin
const int redPin = 11; //The pin number of Red LED
const int bluePin = 10; //The pin number of Blue LED
const int greenPin = 9; //The pin number of Green LED
//Variables that will change
int bright = 0; //Initial value for brightness
int counter = 0; //Initial value for counter
void setup()
{
Serial.begin(9600); //Opens serial port
pinMode(brightnessPin, INPUT); //Sets the brightness pushbutton as INPUT
pinMode(rgbPin, INPUT); //Sets the RGB pushbutton as INPUT
pinMode(redPin, OUTPUT); //Sets the red pin as OUTPUT
pinMode(greenPin, OUTPUT); //Sets the green pin as OUTPUT
pinMode(bluePin, OUTPUT); //Sets the blue pin as OUTPUT
}
void loop()
{
//Reads the state of the pushbutton
int brightState = digitalRead(brightnessPin);
//Checking if the pushbutton is pressed
//If pressed the brightState is HIGH
if (brightState == HIGH)
{
if(counter >=1 && counter <= 4)
{
bright = bright + 51; //The value will increase by 51
analogWrite(redPin, bright); //Stores the value in the red pin
analogWrite(greenPin, bright);//Stores the value in the green pin
analogWrite(bluePin, bright); //Stores the value in blue pin
delay(300); //Waits for 300ms
Serial.println(bright); //Display value in Serial Monitor
}
}
//If bright value exceeds 255
if (bright > 255)
{
bright = 0; //bright's value will revert back to 0
}
//Reads the state of the pushbutton
int buttonState = digitalRead(rgbPin);
//Checking if the pushbutton is pressed
//If pressed the buttonState is HIGH
if (buttonState == HIGH)
{
counter++; //Increase the counter value by 1
delay(500); //Waits for 500ms
Serial.println(counter); //Display value in Serial Monitor
}
//Checking if the counter is triggered
//If triggered it'll change the values of RGB LED
else if (counter == 0)
{
setColor(0,0,0); //Dead state
}
else if (counter == 1)
{
setColor(bright,0,0); //Adjust red value
}
else if (counter == 2)
{
setColor(0,bright,0); //Adjust green value
}
else if (counter == 3)
{
setColor(0,0,bright); //Adjust blue value
}
else if (counter == 4)
{
setColor(bright,bright,bright); //Adjust all values
}
//If the counter went past the condition
else
{
counter = 0; //counter's value will revert back to 0
}
}
//Function return type for RGB
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
2)
int RLEDpin = 3;
int GLEDpin = 6;
int BLEDpin = 5;
int RSensorPin = A0;
int GSensorPin = A1;
int BSensorPin = A2;
int RSensorRead = 0;
int GSensorRead = 0;
int BSensorRead = 0;
int RLEDbright = 0;
int GLEDbright = 0;
int BLEDbright = 0;
//==============================================
void setup(){
pinMode(RLEDpin,OUTPUT);
pinMode(GLEDpin,OUTPUT);
pinMode(BLEDpin,OUTPUT);
}
//==============================================
void loop(){
RSensorRead = analogRead(RSensorPin);
GSensorRead = analogRead(GSensorPin);
BSensorRead = analogRead(BSensorPin);
RLEDbright = map(RSensorRead,0,1023,0,255);
GLEDbright = map(GSensorRead,0,1023,0,255);
BLEDbright = map(BSensorRead,0,1023,0,255);
analogWrite(RLEDpin, RLEDbright);
analogWrite(GLEDpin, GLEDbright);
analogWrite(BLEDpin, BLEDbright);
delay(5); }
3.
int digit_array[11][7] = { { 1,1,1,1,1,1,0 }, // 0 abcdef
{ 0,1,1,0,0,0,0 }, // 1 bc
{ 1,1,0,1,1,0,1 }, // 2 ab de g
{ 1,1,1,1,0,0,1 }, // 3 abcd g
{ 0,1,1,0,0,1,1 }, // 4 bc fg
{ 1,0,1,1,0,1,1 }, // 5 a cd fg
{ 1,0,1,1,1,1,1 }, // 6 a cdefg
{ 1,1,1,0,0,0,0 }, // 7 abc
{ 1,1,1,1,1,1,1 }, // 8 abcdefg
{ 1,1,1,0,0,1,1 }, // 9 abcd fg
{ 0,0,0,0,0,0,1 },}; // - g
//function header
void Digit_Write(int);
void setup()
{
// set pin modes
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop()
{
Digit_Write(0);
delay(1000);
Digit_Write(2);
delay(1000);
Digit_Write(4);
delay(1000);
Digit_Write(6);
delay(1000);
Digit_Write(1);
delay(1000);
Digit_Write(3);
delay(2000);
Digit_Write(5);
delay(1000);
Digit_Write(7);
delay(2000);
}
void Digit_Write(int number)
{
int pin = 6;
for (int j = 0; j < 7; j++)
{
digitalWrite(pin, digit_array[number][j]); //Non-Inverted array value due to use of Common Cathode display
pin++;
}
}
3.
char a=2;
char b=3;
char c=4;
char d=5;
char e=6;
char f=7;
char g=8;
char digit1 = 13;
char digit2 = 12;
char digit3 = 11;
char digit4 = 10;
char Number[10] ={
0b1111110, // 0
0b0110000, // 1
0b1101101, // 2
0b1111001, // 3
0b0110011, // 4
0b1011011, // 5
0b1011111, // 6
0b1110000, // 7
0b1111111, // 8
0b1111011, // 9
};
void display(int n)
{
digitalWrite(a, Number[n] & 0b1000000);
digitalWrite(b, Number[n] & 0b0100000);
digitalWrite(c, Number[n] & 0b0010000);
digitalWrite(d, Number[n] & 0b0001000);
digitalWrite(e, Number[n] & 0b0000100);
digitalWrite(f, Number[n] & 0b0000010);
digitalWrite(g, Number[n] & 0b0000001);
}
void offdisplay()
{
digitalWrite(digit1, 1);
digitalWrite(digit2, 1);
digitalWrite(digit3, 1);
digitalWrite(digit4, 1);
}
void setup()
{
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);
}
void show(int num)
{
char n1 = (num % 10000) / 1000;
char n2 = (num % 1000) / 100;
char n3 = (num % 100) / 10;
char n4 = num % 10;
offdisplay();
display(n1);
digitalWrite(digit1, 0);
delay(2);
offdisplay();
display(n2);
digitalWrite(digit2, 0);
delay(2);
offdisplay();
display(n3);
digitalWrite(digit3, 0);
delay(2);
offdisplay();
display(n4);
digitalWrite(digit4, 0);
delay(2);
}
long t = 0;
int number = 0;
void loop()
{
show(number);
if(millis() - t > 1000)
{
number++;
t = millis();
}
}
|