分类 微控 下的文章

为了把之前挖的说要搭一台UMPC的大坑给填上,必须要有一个足够小的、能当鼠标用的装置,所以就弄出了这么个玩意...首先看看这个项目的原型,Toshiba Libretto系列和Thinkpad 750,都是使用的指点杆然而指点杆太贵了,一个要40多,而且PCB还很大,装不进键盘里,所以实际上和摇杆没什么区别了...那就弄摇杆好了...然后事实证明便宜确实没好货,摇杆转20°左右就满量程了,而且阻尼很大,用起来让人觉得喝了假酒那么要怎么让它用起来稍微好一点呢?因为阻尼大,转起来很难精确控制转动的角度 --> 那就降低光标的移动速度然而这样光标要走过很长的距离时就很痛苦 --> 弄个加速键这样虽然说妥协很大,用起来远远不如小红点顺手,但是...嘿!它能用!再把左键,右键,中键加上之后用一段时间还算顺手,那就这样了吧...既然用了Arduino来当鼠标了,那不加一块屏幕就太浪费了于是就弄了那块128*64,0.96'的OLED屏幕显示下温度,风扇转速和警告信息,看起来相当不错(最终效果见上图)(测试中...)然后是用这玩意解决一些在测试其它系统的时候发现的问题:本来是准备用一个简单的霍尔+MOSFET的独立电路来做到控制主屏幕在开合时的开关的,结果P沟道MOSFET忘买了...再去为了一个MOSFET付十块钱的运费实在是不值,也懒得拿三极管做非门了...那就干脆用Arduino解决算了这里没什么好讲的,就是给栅极10k的下拉电阻似乎太小了,直接上680k下拉解决键盘是买的现成的,拿到手发现虽然质量还行,但是有Z+Shift会和方向左键冲突...本来这不是什么大问题,但是对于东方玩家来说实在致命...于是就弄了个自锁开关,按下会一直按Z,问题解决!最后,还有50%的剩余ROM空间,那就加个非常中二的Boot Screen好了...最后的最后,放下写的稀烂的代码(BootScreen删掉了)#include <Mouse.h> #include <Keyboard.h> #include <U8glib.h> U8GLIB_SSD1306_128X64 u8g(4, 5, 6); const int xPin = A0; const int yPin = A1; const int caliButton = 9; const int caliIndi = 16; const int lButton = 12; const int rButton = 10; const int mainSW = 3; const int scrlSW = 11; const int accSW = 2; const int zButtonSW = 1; const int CPUTempSensor = A5; const int battTempSensor = A4; const int fanPin = 0; const int hallSensor = 7; const int screenMOSFET = 8; //Pin configuration int xCali; int yCali; //Create variables for calibration int xCalied; int yCalied; int xProcessed; int yProcessed; int CPUtemp; int battTemp; int fanSpeed; boolean mouseSwitch; //Declaring variables void setup() { Serial.begin(9600); Mouse.begin(); mouseSwitch = 0; pinMode(accSW, INPUT_PULLUP); u8g.setFont(u8g_font_7x13B); } void loop() { CPUtemp = ((analogRead(CPUTempSensor) - 240) / 11); battTemp = ((analogRead(battTempSensor) - 240) / 11);//Temperature monitoring fanSpeed = (CPUtemp * 6) - 240; if (fanSpeed > 0){ analogWrite(fanPin, fanSpeed); }else{ analogWrite(fanPin, 0); }//Fan control if (digitalRead(hallSensor) == HIGH){ digitalWrite(screenMOSFET, HIGH); }else{ digitalWrite(screenMOSFET, LOW); } int xRaw = analogRead(xPin) - 512; int yRaw = analogRead(yPin) - 512; if (digitalRead(caliButton) == HIGH){ xCali = 0 - xRaw; yCali = 0 - yRaw; digitalWrite(caliIndi, HIGH); }else{ digitalWrite(caliIndi, LOW); } xCalied = (xRaw + xCali)/4; yCalied = (yRaw + yCali)/4; if (digitalRead(accSW) == LOW){ xProcessed = ((10 * cos(0.01 * xCalied)) - 10 + xCalied) / 10; yProcessed = ((10 * cos(0.01 * yCalied)) - 10 + yCalied) / 10; }else{ xProcessed = ((10 * cos(0.01 * xCalied)) - 10 + xCalied) / 16; yProcessed = ((10 * cos(0.01 * yCalied)) - 10 + yCalied) / 16; } if (digitalRead(mainSW) ==HIGH){ mouseSwitch = 1; }else{ mouseSwitch = 0; } if (mouseSwitch ==1){ if (digitalRead(lButton) == HIGH){ Mouse.press(MOUSE_LEFT); }else{ Mouse.release(MOUSE_LEFT); } if (!(digitalRead(rButton) == HIGH && digitalRead(scrlSW) == HIGH)){ if (digitalRead(rButton) == HIGH){ Mouse.press(MOUSE_RIGHT); }else{ Mouse.release(MOUSE_RIGHT); } if (digitalRead(scrlSW) == HIGH){ Mouse.move(0, 0, xProcessed / 4); }else{ Mouse.move(yProcessed, -xProcessed); } Mouse.release(MOUSE_MIDDLE); }else{ Mouse.press(MOUSE_MIDDLE); Mouse.move(yProcessed, -xProcessed); } } if (digitalRead(zButtonSW) == HIGH){ Keyboard.press('z'); }else{ Keyboard.release('z'); } u8g.firstPage(); do{ u8g.setFont(u8g_font_7x13B); u8g.drawFrame(2, 2, 126, 62); u8g.drawStr(4, 13, "CPU Temp:"); u8g.setPrintPos(70, 12); u8g.print(CPUtemp); u8g.drawStr(4, 27, "Batt Temp:"); u8g.setPrintPos(77, 27); u8g.print(battTemp); u8g.drawStr(105, 62, "RPM"); u8g.drawLine(105, 50, 126, 50); u8g.drawLine(105, 6, 126, 6); if (fanSpeed > 0){ u8g.drawLine(108, (-(fanSpeed / 6) + 50), 123, (-(fanSpeed / 6) + 50)); } u8g.drawStr(22, 48, "[ ][ ][ ]"); if (battTemp > 50){ u8g.drawStr(29, 48, "!"); } if (digitalRead(caliButton) == HIGH){ u8g.drawStr(50, 48, "*"); } if (digitalRead(zButtonSW) == HIGH){ u8g.drawStr(73, 48, "Z"); } } while(u8g.nextPage()); }By Zephyr2552020/8/21