반응형

AudioSwitcher를 이용해 시스템 볼륨을 조정해 보자.

 

AudioSwitcher Nuget Package를 설치한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using System.Runtime.InteropServices;
using AudioSwitcher.AudioApi.CoreAudio;
 
namespace ConsoleApp1
{
    class Program
    {
        [DllImport("kernel32.dll")]
        static extern IntPtr GetConsoleWindow();
 
        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
 
        static void Main(string[] args)
        {
            const int SW_HIDE = 0// 창 숨기기
            const int SW_SHOW = 1// 창 보이기
 
            IntPtr handle = GetConsoleWindow();
            //ShowWindow(handle, SW_HIDE);
 
            CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;
            Console.WriteLine("Current Volume: " + defaultPlaybackDevice.Volume);
 
            while (true)
            {
                if (defaultPlaybackDevice.Volume > 20// 볼륨이 20 보다 크다면
                {
                    while (defaultPlaybackDevice.Volume > 20// 볼륨이 20 보다 크지 않을때 까지 무한 루프
                    {
                        defaultPlaybackDevice.Volume--// 볼륨 1 감소
                        Console.WriteLine("Current Volume: " + defaultPlaybackDevice.Volume);
                        System.Threading.Thread.Sleep(1000); // 매 1초 확인
                    }
                }
 
                System.Threading.Thread.Sleep(10000); // 매 10초 확인
            }
        }
    }
}
 

 

소스를 입력하고 빌드한다.

 

프로그램을 실행하면 시스템 볼륨이 20 이하일 때까지 1초마다 1씩 감소한다.

 

처음 35였던 볼륨이 20이 되었다.

 

2022.01.07 - [C#] - C# AudioSwitcher System Audio/Sound Volume Control - 시스템 오디오/사운드 볼륨 컨트롤 2

 

반응형
Posted by J-sean
:
반응형

예전 영화에서 종종 볼 수 있던 레이저 침입 감지 시스템은 간단한 작동 원리에도 불구하고 레이저를 이용 한 방식이 뭔가 있어 보이는지 아직까지도 영화나 드라마에서 심심치 않게 볼 수 있다. 작동 원리가 간단한 만큼 저렴한 부품으로도 비슷하게 만들어 볼 수 있다.


침입 감지 시스템을 회피하기 위한 Catherine Zeta-Jones의 피나는 노력 (영화 Entrapment)


The Big Bang Theory


약 $0.4 짜리 레이저 모듈. 5V로 작동하고 출력 5mW, 파장 650nm의 붉은색 레이저를 발생 시킨다.


Red 

625 - 740nm

Orange

590 - 625nm

Yellow

565 - 590nm

Green

520 - 565nm

Cyan

500 - 520nm

Blue

435 - 500nm

Violet

380 - 435nm


약 $0.7 짜리 레이저 수신 모듈. 5V로 작동하고, 레이저가 수신 될때는 HIGH 시그널을, 수신 되지 않을때는 LOW 시그널을 출력 한다. 수신하려는 레이저 외, 태양이나 다른 강한 빛이 없는 실내용.



레이저 리시버 센서는 방향에 주의 한다. 반대로 연결하면 뜨거울 정도로 열이 발생 한다.


위 다이어그램과 같이 구성 한다.


레이저 모듈에서 레이저가 발생되고 수신 모듈에서 이 레이저를 감지하면 HIGH 시그널을 출력 한다.


중간에 장애물이 생겨 레이저를 수신하지 못하게 되면 수신 모듈에서 LOW 시그널을 출력하고 아두이노는 디지털 4번 핀으로 HIGH를 출력해 Buzzer를 작동 시킨다.



실제 부품의 연결 방식은 다이어그램과 다르지만 기본 구성은 동일 하다. 


소스를 컴파일하고 아두이노에 업로드 한다.


제작 과정 및 테스트


Serial Monitor에도 적의 침입 기록이 남는다.


반응형
Posted by J-sean
:
반응형

It describes how to draw the simple solar system that is composed of the Sun, the Earth and the Moon.

OpenGL로 태양, 지구, 달로 구성된 간단한 태양계 그리기


1 day = 10 frames

1 month = 30 days (300 frames)

1 year = 12 months (3,600 frames)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <gl/glut.h>
#include <iostream>
 
GLfloat EarthRotation = 0.0f;
GLfloat MoonRevolution = 0.0f;
GLfloat EarthRevolution = 0.0f;
 
GLfloat FramePerYear = 3600.0f;
GLint delay = 10;
 
GLint Year = 2020;
GLint Month = 1;
GLint Day = 1;
 
void MyDisplay();
void MyTimer(int value);
 
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("OpenGL Solar System");
 
    gluLookAt(
        0.01.00.0,    // Eye
        0.00.00.0,    // Center
        1.00.01.0    // Up
    );
    // gluLookAt creates a viewing matrix derived from an eye point, a reference point indicating
    // the center of the scene, and an UP vector.
 
    glutTimerFunc(delay, MyTimer, 1);
    glutDisplayFunc(MyDisplay);
    
    glutMainLoop();
 
    return 0;
}
 
void MyDisplay()
{
    glClear(GL_COLOR_BUFFER_BIT);
    
    // The Sun
    glutWireSphere(0.44020);
    
    // The Earth
    glPushMatrix();
    glRotatef(EarthRevolution, 0.0f1.0f0.0f); // Earth's revolution
    glTranslatef(0.7f0.0f0.0f);
    
    glRotatef(-EarthRevolution, 0.0f1.0f0.0f);    // Earth의 Revolution에 의한 Earth의 회전 삭제.
    glRotatef(EarthRotation, 0.0f1.0f0.0f);    // Earth's rotation
    glutWireSphere(0.12010);
 
        // The Moon
        glPushMatrix();
        glRotatef(-EarthRotation, 0.0f1.0f0.0f);    // Earth의 Rotation에 의한 Moon의 회전 삭제.
        glRotatef(MoonRevolution, 0.0f1.0f0.0f); // Moon's revolution
        glTranslatef(0.2f0.0f0.0f);
        glutWireSphere(0.03105);
        glPopMatrix();
 
    glPopMatrix();
    
    glutSwapBuffers();
}
 
void MyTimer(int value)
{
    EarthRotation += (360.0f * 360.0f/ FramePerYear;    // 지구 자전: (360도 * 360일) / FramePerYear(3600) = 36도
    if (EarthRotation >= 360.0f) {
        EarthRotation = 0.0f;
 
        std::cout << Year << "-" << Month << "-" << Day << std::endl;
        // 날짜 출력 코드가 계산 코드(Day++, Month++, Year++)보다 먼저 처리 되야 제대로 표시 된다.
 
        Day++;
        if (Day > 30)
            Day = 1;
    }
 
    MoonRevolution += (360.0f * 12.0f/ FramePerYear;
    // 달의 공전 주기는 약27일 이지만 30일(1달)로 설정.
    // Rotation은 Revolution 과 같은 주기로 따로 계산할 필요 없음.
    // Revolution 처리 만으로 항상 달의 같은면이 지구를 바라 봄.
    if (MoonRevolution >= 360.0f) {
        MoonRevolution = 0.0f;
 
        Month++;
        if (Month > 12)
            Month = 1;
    }
 
    EarthRevolution += 360.0f / FramePerYear;    // 1 프레임에 0.1도 회전. 3600 프레임이 1년.
    if (EarthRevolution >= 360.0f) {
        EarthRevolution = 0.0f;
 
        Year++;
    }
    
    glutPostRedisplay();
    glutTimerFunc(delay, MyTimer, 1);
}



Run the program and see how it works.


반응형
Posted by J-sean
: