五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Arduino觸摸傳感簡(jiǎn)化代碼:

2020-06-06 15:34 作者:dustymirror  | 我要投稿

//引腳觸摸傳感器 控制LED亮度 2020 dusty electronix

//https://www.bilibili.com/video/BV1of4y127ow



int capval2,capval3;//設(shè)定2、3引腳電容值變量

int led9,led11;


void setup()


{


Serial.begin(9600);//與電腦串口通訊


}


void loop ()


{


capval2 = readCapacitivePin(2);? ?//讀取2引腳電容數(shù)值


capval3 = readCapacitivePin(3);? ?//讀取3引腳電容數(shù)值


Serial.print("pin2:");

? ?Serial.println(capval2);//顯示2引腳電容數(shù)值


led9 = map(capval2,2,17,0,255);//轉(zhuǎn)換2引腳電容數(shù)值為led9亮度值

analogWrite(9, led9);//寫入led9亮度

??

Serial.print("pin3:");

? ?Serial.println(capval3);//顯示3引腳電容數(shù)值


led11 = map(capval3,2,17,0,255);//轉(zhuǎn)換3引腳電容數(shù)值為led11亮度值

analogWrite(11, led11);//寫入led11亮度


delay(100);//悠著點(diǎn)


}




//原始代碼


uint8_t readCapacitivePin(int pinToMeasure) {


// Variables used to translate from Arduino to AVR pin naming


volatile uint8_t* port;


volatile uint8_t* ddr;


volatile uint8_t* pin;


// Here we translate the input pin number from


// Arduino pin number to the AVR PORT, PIN, DDR,


// and which bit of those registers we care about.


byte bitmask;


port = portOutputRegister(digitalPinToPort(pinToMeasure));


ddr = portModeRegister(digitalPinToPort(pinToMeasure));


bitmask = digitalPinToBitMask(pinToMeasure);


pin = portInputRegister(digitalPinToPort(pinToMeasure));


// Discharge the pin first by setting it low and output


*port &= ~(bitmask);


*ddr |= bitmask;


delay(1);


// Make the pin an input with the internal pull-up on


*ddr &= ~(bitmask);


*port |= bitmask;


// Now see how long the pin to get pulled up. This manual unrolling of the loop


// decreases the number of hardware cycles between each read of the pin,


// thus increasing sensitivity.


uint8_t cycles = 17;


if (*pin & bitmask)


cycles = 0;


else if (*pin & bitmask)


cycles = 1;


else if (*pin & bitmask)


cycles = 2;


else if (*pin & bitmask)


cycles = 3;


else if (*pin & bitmask)


cycles = 4;


else if (*pin & bitmask)


cycles = 5;


else if (*pin & bitmask)


cycles = 6;


else if (*pin & bitmask)


cycles = 7;


else if (*pin & bitmask)


cycles = 8;


else if (*pin & bitmask)


cycles = 9;


else if (*pin & bitmask)


cycles = 10;


else if (*pin & bitmask)


cycles = 11;


else if (*pin & bitmask)


cycles = 12;


else if (*pin & bitmask)


cycles = 13;


else if (*pin & bitmask)


cycles = 14;


else if (*pin & bitmask)


cycles = 15;


else if (*pin & bitmask)


cycles = 16;


// Discharge the pin again by setting it low and output


// It's important to leave the pins low if you want to


// be able to touch more than 1 sensor at a time - if


// the sensor is left pulled high, when you touch


// two sensors, your body will transfer the charge between


// sensors.


*port &= ~(bitmask);


*ddr |= bitmask;


return cycles;


}


//原始代碼完


Arduino觸摸傳感簡(jiǎn)化代碼:的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
游戏| 和龙市| 遂川县| 博野县| 阿拉善右旗| 临潭县| 武义县| 丹寨县| 元氏县| 嘉善县| 淳化县| 定安县| 祁连县| 铜川市| 平昌县| 青浦区| 湖口县| 香格里拉县| 内丘县| 濮阳市| 满城县| 平昌县| 靖州| 汉源县| 姜堰市| 呼和浩特市| 绩溪县| 海丰县| 都江堰市| 云南省| 璧山县| 康平县| 廊坊市| 平南县| 白山市| 西充县| 临猗县| 建始县| 繁峙县| 泰兴市| 左云县|