[入门]程序员专用键盘 精华

4058浏览
查看: 4058|回复: 1

[入门] 程序员专用键盘

[复制链接]
本帖最后由 question 于 2021-6-22 20:27 编辑

闲着没事搞个键盘玩玩,上正片哈哈。
打开立创eda,点下这个 点下那个就这样了。
程序员专用键盘图1

立创直接打板

程序员专用键盘图2
程序员专用键盘图7
rgb灯 热插拔轴,玩得有点hi
rgb测试代码
  1. // NeoPixel test program showing use of the WHITE channel for RGBW
  2. // pixels only (won't look correct on regular RGB NeoPixel strips).
  3. #include <Adafruit_NeoPixel.h>
  4. #ifdef __AVR__
  5. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  6. #endif
  7. // Which pin on the Arduino is connected to the NeoPixels?
  8. // On a Trinket or Gemma we suggest changing this to 1:
  9. #define LED_PIN     A5
  10. // How many NeoPixels are attached to the Arduino?
  11. #define LED_COUNT  3
  12. // NeoPixel brightness, 0 (min) to 255 (max)
  13. #define BRIGHTNESS 50 // Set BRIGHTNESS to about 1/5 (max = 255)
  14. // Declare our NeoPixel strip object:
  15. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
  16. // Argument 1 = Number of pixels in NeoPixel strip
  17. // Argument 2 = Arduino pin number (most are valid)
  18. // Argument 3 = Pixel type flags, add together as needed:
  19. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  20. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  21. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  22. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  23. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  24. void setup() {
  25.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  26.   // Any other board, you can remove this part (but no harm leaving it):
  27. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  28.   clock_prescale_set(clock_div_1);
  29. #endif
  30.   // END of Trinket-specific code.
  31.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  32.   strip.show();            // Turn OFF all pixels ASAP
  33.   strip.setBrightness(BRIGHTNESS);
  34. }
  35. void loop() {
  36.   // Fill along the length of the strip in various colors...
  37.   colorWipe(strip.Color(255,   0,   0)     , 50); // Red
  38.   colorWipe(strip.Color(  0, 255,   0)     , 50); // Green
  39.   colorWipe(strip.Color(  0,   0, 255)     , 50); // Blue
  40.   colorWipe(strip.Color(  0,   0,   0, 255), 50); // True white (not RGB white)
  41.   whiteOverRainbow(75, 5);
  42.   pulseWhite(5);
  43.   rainbowFade2White(3, 3, 1);
  44. }
  45. // Fill strip pixels one after another with a color. Strip is NOT cleared
  46. // first; anything there will be covered pixel by pixel. Pass in color
  47. // (as a single 'packed' 32-bit value, which you can get by calling
  48. // strip.Color(red, green, blue) as shown in the loop() function above),
  49. // and a delay time (in milliseconds) between pixels.
  50. void colorWipe(uint32_t color, int wait) {
  51.   for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  52.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  53.     strip.show();                          //  Update strip to match
  54.     delay(wait);                           //  Pause for a moment
  55.   }
  56. }
  57. void whiteOverRainbow(int whiteSpeed, int whiteLength) {
  58.   if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
  59.   int      head          = whiteLength - 1;
  60.   int      tail          = 0;
  61.   int      loops         = 3;
  62.   int      loopNum       = 0;
  63.   uint32_t lastTime      = millis();
  64.   uint32_t firstPixelHue = 0;
  65.   for(;;) { // Repeat forever (or until a 'break' or 'return')
  66.     for(int i=0; i<strip.numPixels(); i++) {  // For each pixel in strip...
  67.       if(((i >= tail) && (i <= head)) ||      //  If between head & tail...
  68.          ((tail > head) && ((i >= tail) || (i <= head)))) {
  69.         strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
  70.       } else {                                             // else set rainbow
  71.         int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  72.         strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  73.       }
  74.     }
  75.     strip.show(); // Update strip with new contents
  76.     // There's no delay here, it just runs full-tilt until the timer and
  77.     // counter combination below runs out.
  78.     firstPixelHue += 40; // Advance just a little along the color wheel
  79.     if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
  80.       if(++head >= strip.numPixels()) {      // Advance head, wrap around
  81.         head = 0;
  82.         if(++loopNum >= loops) return;
  83.       }
  84.       if(++tail >= strip.numPixels()) {      // Advance tail, wrap around
  85.         tail = 0;
  86.       }
  87.       lastTime = millis();                   // Save time of last movement
  88.     }
  89.   }
  90. }
  91. void pulseWhite(uint8_t wait) {
  92.   for(int j=0; j<256; j++) { // Ramp up from 0 to 255
  93.     // Fill entire strip with white at gamma-corrected brightness level 'j':
  94.     strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  95.     strip.show();
  96.     delay(wait);
  97.   }
  98.   for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
  99.     strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  100.     strip.show();
  101.     delay(wait);
  102.   }
  103. }
  104. void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
  105.   int fadeVal=0, fadeMax=100;
  106.   // Hue of first pixel runs 'rainbowLoops' complete loops through the color
  107.   // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
  108.   // just count from 0 to rainbowLoops*65536, using steps of 256 so we
  109.   // advance around the wheel at a decent clip.
  110.   for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
  111.     firstPixelHue += 256) {
  112.     for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  113.       // Offset pixel hue by an amount to make one full revolution of the
  114.       // color wheel (range of 65536) along the length of the strip
  115.       // (strip.numPixels() steps):
  116.       uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  117.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  118.       // optionally add saturation and value (brightness) (each 0 to 255).
  119.       // Here we're using just the three-argument variant, though the
  120.       // second value (saturation) is a constant 255.
  121.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
  122.         255 * fadeVal / fadeMax)));
  123.     }
  124.     strip.show();
  125.     delay(wait);
  126.     if(firstPixelHue < 65536) {                              // First loop,
  127.       if(fadeVal < fadeMax) fadeVal++;                       // fade in
  128.     } else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
  129.       if(fadeVal > 0) fadeVal--;                             // fade out
  130.     } else {
  131.       fadeVal = fadeMax; // Interim loop, make sure fade is at max
  132.     }
  133.   }
  134.   for(int k=0; k<whiteLoops; k++) {
  135.     for(int j=0; j<256; j++) { // Ramp up 0 to 255
  136.       // Fill entire strip with white at gamma-corrected brightness level 'j':
  137.       strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  138.       strip.show();
  139.     }
  140.     delay(1000); // Pause 1 second
  141.     for(int j=255; j>=0; j--) { // Ramp down 255 to 0
  142.       strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  143.       strip.show();
  144.     }
  145.   }
  146.   delay(500); // Pause 1/2 second
  147. }
复制代码
键盘测试代码
  1. #include "Adafruit_Keypad.h"
  2. const byte ROWS = 2; // rows
  3. const byte COLS = 2; // columns
  4. //define the symbols on the buttons of the keypads
  5. char keys[ROWS][COLS] = {
  6.   {'1','2'},
  7.   {'3','4'}
  8. };
  9. byte rowPins[ROWS] = { 3, 2}; //connect to the row pinouts of the keypad
  10. byte colPins[COLS] = {15, 16}; //connect to the column pinouts of the keypad
  11. //initialize an instance of class NewKeypad
  12. Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
  13. void setup() {
  14.   Serial.begin(9600);
  15.   customKeypad.begin();
  16. }
  17. void loop() {
  18.   // put your main code here, to run repeatedly:
  19.   customKeypad.tick();
  20.   while(customKeypad.available()){
  21.     keypadEvent e = customKeypad.read();
  22.     Serial.print((char)e.bit.KEY);
  23.     if(e.bit.EVENT == KEY_JUST_PRESSED) Serial.println(" pressed");
  24.     else if(e.bit.EVENT == KEY_JUST_RELEASED) Serial.println(" released");
  25.   }
  26.   delay(10);
  27. }
复制代码

自己根据需求改键盘代码就好
生产资料在下面
程序员专用键盘图5
程序员专用键盘图4
程序员专用键盘图3


下载附件Gerber_pcb.zip








hnyzcj  版主

发表于 2021-6-23 06:15:12

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail