[C++] ctime–Finding Weekday

#include<iostream>
#include<ctime>
using namespace std;
int main() {
 tm time{0,0,0,21,1-1,2017-1900};
 mktime(&time);
 cout << time.tm_wday << endl;
 system("pause");
 return 0;
}
tm:
 int tm_sec; // seconds after the minute - [0, 60] including leap second
 int tm_min; // minutes after the hour - [0, 59]
 int tm_hour; // hours since midnight - [0, 23]
 int tm_mday; // day of the month - [1, 31]
 int tm_mon; // months since January - [0, 11]
 int tm_year; // years since 1900
 int tm_wday; // days since Sunday - [0, 6]
 int tm_yday; // days since January 1 - [0, 365]
 int tm_isdst; // daylight savings time flag

[Python] operator.itemgetter

Word Counter Sorted by Times(Chinese Version):

import operator
in_file = open("input.txt")
raw_article = in_file.read()
table={}
for word in raw_article:
 if word in table:
   table[word] = table[word]+1
 else:
   table[word] = 1
sorted_table = sorted(table.items(),key=operator.itemgetter(1),reverse=True)
for pair in sorted_table:
 print(pair[0],":",pair[1])

[Python] Anaconda

  • numpy and matplotlib
import numpy as np
import matplotlib.pyplot as pt
x = np.arange(0,360)
y = np.sin(x*np.pi/180)
pt.plot(x,y)
pt.xlim(0,360)
pt.ylim(-2,2)
pt.title("SINE")
pt.show()
%e6%9c%aa%e5%91%bd%e5%90%8d

[Python] requests

import requests
www = requests.get("http://www.google.com")
print(www.text)

[Linux] Kernel Version

cat   /proc/version

uname   -a
#lsb_release -a

LSB Version: 1.3

Distributor ID: RedHatEnterpriseAS

Descrīption: Red Hat Enterprise Linux AS release 4 (Nahant Update 1)

Release: 4

Codename: NahantUpdate1

[Arduino] Final Project

#include<dht11.h>
#include<LiquidCrystal.h>
LiquidCrystal LCD(11,12,5,4,3,2); //宣告一個名為LCD的LiquidCrystal
dht11 DHT; //宣告一個名為DHT的dht11
int trig = 9,echo = 10,buzzer = 6;
float cm;
void setup() {
    LCD.begin(16,2); //初始化LCD
    pinMode(buzzer,OUTPUT); //初始化蜂鳴器
    pinMode(trig,OUTPUT); //初始化超音波發射器為OUTPUT
    pinMode(echo,INPUT); //初始化超音波接收器為INPUT
}
void loop() {
    if(DHT.read(8) == 0) //如果讀取成功輸出溫度和濕度
    { 
        showdht(); //顯示溫度濕度
        bibi(); //蜂鳴器叫兩聲
        delay(2000);
        LCD.clear(); 
        showdis(); //顯示距離
        bibi();
        delay(2000); 
    }
    else{ //讀取失敗則輸出Error
    LCD.setCursor(0,0);
    LCD.print("Error");
    }
    LCD.clear(); //清除畫面 
}
void bibi() //嗶嗶兩聲
{
    for(int i = 1;i <= 100;i++) //每隔4ms鳴叫一次重複100次
    {
        digitalWrite(buzzer,HIGH);
        delay(1);
        digitalWrite(buzzer,LOW);
        delay(1);
    }
    delay(100);
    for(int i = 1;i <= 100;i++) //每隔4ms鳴叫一次重複100次
    {
        digitalWrite(buzzer,HIGH);
        delay(1);
        digitalWrite(buzzer,LOW);
        delay(1);
    }
}
void showdht() //用來輸出溫度濕度
{
    LCD.setCursor(0,0);
    LCD.print("Temperature:");
    LCD.print((float)DHT.temperature,2);
    LCD.print("c");
    LCD.setCursor(0,1);
    LCD.print("Humidity:");
    LCD.print((float)DHT.humidity,2);
    LCD.print("%"); 
}
void showdis() //用來計算和輸出距離
{
    //trig發出脈衝
    digitalWrite(trig,LOW);
    delayMicroseconds(2);
    digitalWrite(trig,HIGH);
    delayMicroseconds(10);
    digitalWrite(trig,LOW);
    //接收時間
    long etime = pulseIn(echo,HIGH);//等到pin到HIGH之後開始計時直到LOW 回傳Microseconds;
    //計算距離
    cm = etime*(331+0.6*(float)DHT.temperature)/2/10000;
    LCD.setCursor(0,0);
    LCD.print("Distance:");
    LCD.setCursor(0,1);
    LCD.print(cm);
    LCD.print("cm"); 
}

[Arduino]

#include<dht11.h>
#include<LiquidCrystal.h>
LiquidCrystal LCD(12,11,2,3,4,5); //宣告一個名為LCD的LiquidCrystal
dht11 DHT; //宣告一個名為DHT的dht11
void setup() {
    LCD.begin(16,2); //初始化LCD
}
void loop() {
    if(DHT.read(13) == 0) //如果讀取成功輸出溫度和濕度
    {
        LCD.setCursor(0,0);
        LCD.print("Temperature:");
        LCD.print((float)DHT.temperature,2);
        LCD.print("c");
        LCD.setCursor(0,1);
        LCD.print("Humidity:");
        LCD.print((float)DHT.humidity,2);
        LCD.print("%"); 
    }
    else{ //讀取失敗則輸出Error
        LCD.setCursor(0,0);
        LCD.print("Error");
    }
    delay(2000); //等待兩秒後清除畫面
    LCD.clear();
}

[Arduino] LCM

#include<LiquidCrystal.h>
LiquidCrystal LCD(12,11,2,3,4,5); //宣告一個名為LCD的LiquidCrystal
byte left[8] = {B00100,B01000,B10000,B00000,B00000,B00000,B00000,B00000}; //符號ˊ
byte dot[8] = {B00000,B01100,B01100,B00000,B00000,B00000,B00000,B00000}; //符號・
byte right[8] = {B00100,B00010,B00001,B00000,B00000,B00000,B00000,B00000}; //符號ˋ
void setup() {
    //創建字元
    LCD.createChar(0,left);
    LCD.createChar(1,dot); 
    LCD.createChar(2,right);
    LCD.begin(16,2);
    LCD.print("Hello,World!");
    //在(5,1)印出(´・ω・`)
    LCD.setCursor(5,1);
    LCD.write("(");
    LCD.write(byte(0));
    LCD.write(byte(1));
    LCD.write("w");
    LCD.write(byte(1));
    LCD.write(byte(2));
    LCD.write(")");
}
void loop() {
    //在(0,1)印出經過時間(秒)
    LCD.setCursor(0,1);
    LCD.print(millis()/1000);
}

[Arduino] Ultrasound

int trig = 8;
int echo = 9;
int led[7] = {0,1,2,3,4,5,6};
float cm,inch;
void setup() {
    pinMode(trig,OUTPUT); //初始化超音波發射器為OUTPUT
    pinMode(echo,INPUT); //初始化超音波接收器為INPUT
    for(int i = 1;i <= 6;i++)pinMode(led[i],OUTPUT); //初始化六個LED
    Serial.begin(9600); //初始化序列埠傳輸速率
    //delay(3000);
    Serial.println("ShowDistance : ");
}

void loop() {
    //trig發出脈衝
    digitalWrite(trig,LOW);
    delayMicroseconds(2);
    digitalWrite(trig,HIGH);
    delayMicroseconds(10);
    digitalWrite(trig,LOW);
    //接收時間
    long etime = pulseIn(echo,HIGH);//等到pin到HIGH之後開始計時直到LOW 回傳Microseconds;
    //計算距離
    cm = etime/29/2;
    inch = etime/74/2;
    Serial.print(cm);
    Serial.println("cm");
    Serial.print(inch);
    Serial.println("inch");
    for(int i = 1;i <= 6;i++) //全部LED熄滅
    {
        digitalWrite(led[i],LOW);
    }
    for(int i = 1;i <= ((cm/10)+1)&&i <= 6;i++) //判斷需有幾個燈亮並點亮
    {
        digitalWrite(led[i],HIGH);
    }
    delay(500); //每500毫秒更新一次距離
}