自制简易led手电筒

闲来无事哥自制的手电筒,晚上可以放键盘边上照明,没什么技术含量,先来说一下步骤:

step1:

搞一个9v的电池,前些日子玩arduino剩下的电池,找一节没电的把上面的帽子给弄下来。这个给电池脱衣服的时候小心一点不要伤到手。

                                  20120422_001   20120422_003

阅读全文…

ubuntu 修改分辨率

为需要装了ubuntu,发现显示分辨率只有800*600,刷新60,在1280*1024的显示器里看的实在难受。我的机器是intel的集成显卡,下面是我的设置过程:

1.命令行:cvt <你需要的分辨率><空格><刷新率>

如我想设置1280*1024,刷新75,于是输入 cvt 1280 1024 75 回车,得到的Modeline信息才是我们需要的,如:

root@mypc:~# cvt 1280 1024 75

# 1280×1024 74.90 Hz (CVT 1.31M4) hsync: 80.30 kHz; pclk: 138.75 MHz

Modeline “1280x1024_75.00″ 138.75 1280 1368 1504 1728 1024 1027 1034 1072 -hsync +vsync

复制红色的一行。

2.命令行:sudo gedit /etc/X11/xorg.conf 打开配置文件,没有此文件没关系,修改后保全就有了。

在此文件加入如下内容:

Section “Monitor”

Identifier “Configured Monitor”

Modeline “1280x1024_75.00″ 138.75 1280 1368 1504 1728 1024 1027 1034 1072 -hsync +vsync

Option “PreferredMode” “1280x1024_75.00″

EndSection

Section “Screen”

Identifier “Default Screen”

Monitor “Configured Monitor”

Device “Configured Video Device”

EndSection

Section “Device”

Identifier “Configured Video Device”

EndSection

上面红色的是根据不同配置要修改的地方,修改完毕保存重启即可。其实重要的是cvt这个命令了。

wordpress评论防止恶意评论方法

wordpress评论防止恶意评论方法:在主题的function.php文件加入如下函数,这样之后那些家伙们留下的连接就不会流失权重了。

//访客链接新窗口打开
function comment_author_link_window()
{
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();
$home = get_option('home');
if ( empty( $url ) ¦¦ 'http://' == $url )
$return = $author;
else
$return = "<a href='$home?url=$url' rel='external nofollow' target='_blank'>$author</a>";
return $return;
}
add_filter('get_comment_author_link', 'comment_author_link_window');
//开启评论链接地址重写
function redirect_comment_link()
{
$redirect = $_GET['url'];
if($redirect){
if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
header("Location: $redirect");
exit;
} else {
header("Location:".get_option('home'));
exit;
}
}
}
add_action('init', 'redirect_comment_link');

 

卡尔曼滤波函数

static const float dt = 0.02; 

static float P[2][2] = {{ 1, 0 }, { 0, 1 }}; 

float angle;
float q_bias;
float rate; 

static const float R_angle = 0.5 ;
static const float Q_angle = 0.001;
static const float Q_gyro  = 0.003; 

float stateUpdate(const float gyro_m){ 

float q;
float Pdot[4];
q = gyro_m - q_bias;
Pdot[0] = Q_angle - P[0][1] - P[1][0];    /* 0,0 */
Pdot[1] = - P[1][1];             /* 0,1 */
Pdot[2] = - P[1][1];                 /* 1,0 */
Pdot[3] = Q_gyro;     /* 1,1 */ 

rate = q; 

angle += q * dt; 

P[0][0] += Pdot[0] * dt;
P[0][1] += Pdot[1] * dt;
P[1][0] += Pdot[2] * dt;
P[1][1] += Pdot[3] * dt; 

return angle;
} 

float kalmanUpdate(const float incAngle)
{ 

float angle_m = incAngle;
float angle_err = angle_m - angle; 

float h_0 = 1; 

const float PHt_0 = h_0*P[0][0]; /* + h_1*P[0][1] = 0*/
const float PHt_1 = h_0*P[1][0]; /* + h_1*P[1][1] = 0*/ 

float E = R_angle +(h_0 * PHt_0); 

float K_0 = PHt_0 / E;
float K_1 = PHt_1 / E; 

float Y_0 = PHt_0;  /*h_0 * P[0][0]*/
float Y_1 = h_0 * P[0][1]; 

P[0][0] -= K_0 * Y_0;
P[0][1] -= K_0 * Y_1;
P[1][0] -= K_1 * Y_0;
P[1][1] -= K_1 * Y_1; 

angle += K_0 * angle_err;
q_bias += K_1 * angle_err; 

return angle;

arduino常用代码,控制基本组件


一、HC-SR501人体红外感应模块

//红外感应
//信号接 7 端口
int ledpin = 7;

void setup()
{
  pinMode(ledpin, INPUT);
  Serial.begin(9600);  // 打开串口,设置波特率为9600 bps
}

void loop()
{
  int in = digitalRead(ledpin);
  Serial.println(in); //有人的时候输出高电平1 无人0
  delay(2000);
} 

二、超声波测距模块

//超声波测距
//Echo 接 arduino.5;Trig 接 arduino.4
//VCC +,END - GND 无需外接电源即可测试

const int TrigPin = 4;
const int EchoPin = 5;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in centimeters:
  long duration, cm;

  // The HC-SR04 is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(TrigPin, OUTPUT);
  digitalWrite(TrigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(TrigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(TrigPin, LOW);

  // The same pin is used to read the signal from the HC-SR04: a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(EchoPin, INPUT);
  duration = pulseIn(EchoPin, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);

  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

  delay(1000);
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

三、直流电机控制模块测试

//直流电机控制
//需要外接电源 5V - 12V
//VCC接 arduino +5,GND 接 arduino GND
//1INA 1INB 分别接 arduino PWM 6,7
int leftmotorpin1 = 7;  // define your motor pins
int leftmotorpin2 = 6;

void setup()
{
  for (int pinindex = 0; pinindex < 14; pinindex++) {
    pinMode(pinindex, OUTPUT);  // set pins 0 to 13 as outputs
  }
  Serial.begin(9600);  // 打开串口,设置波特率为9600 bps
}
void loop()
{
  Serial.println("run");
  digitalWrite(leftmotorpin1, HIGH);
  digitalWrite(leftmotorpin2, LOW);
  delay(5000);
  Serial.println("back");
  digitalWrite(leftmotorpin1, LOW);
  digitalWrite(leftmotorpin2, HIGH);
  delay(5000);
  Serial.println("stop");
  digitalWrite(leftmotorpin1, LOW);
  digitalWrite(leftmotorpin2, LOW);
  delay(3000);
} 

四、带光耦的电机驱动

//需要外接电源 +5V - +12V
//舵机接5+ arduino.GND  型号端接 arduino.PWM 9
#include <Servo.h>
Servo myservo;//定义舵机变量名
void setup()
{
  myservo.attach(9);//定义舵机接口,9或10
  Serial.begin(9600);  // 打开串口,设置波特率为9600 bps
}
void loop()
{
  for(int i=0;i<=18;i++)
  {
    myservo.write(i * 10);//设置舵机旋转的角度
    Serial.println(i * 10);
    delay(1000);
  }
}

arduino 控制74hc595驱动led

用74hc595最好的效果就是省io口,这玩意简单的说就是而是将八位二进制数通过八只脚同时输出,,串行的一个一个输出,然后并行同时输出。。

Q0-Q7这8个脚就是输出脚

vcc接5V

GUN接地

MR是主复位针脚低电平有效,所以我们要给他加高电平,一样接到5v上面

OE是输出控制器,低电平才能让芯片输出,所以我们将它接到地线上

然后将DS(pin14)接到arduino的11号数字口上,SH_CP(pin11)接到arduino12号数字口,ST_CP(pin12)接到arduino的8号口上(后面这三个针脚接arduino针脚按自己喜好接,程序中定义好就行了,无所谓的)

以led演示为例

int latchPin = 8;
int clockPin = 12;
int dataPin = 11; //这里定义了那三个脚
void setup ()
{
   pinMode(latchPin,OUTPUT);
   pinMode(clockPin,OUTPUT);
    pinMode(dataPin,OUTPUT); //让三个脚都是输出状态
}
void loop()
{
   for(int a=0; a>255; a++)
  /*这个循环的意思是让a这个变量+1一直加到到255,每次循环都进行下面的活动*/
      {
          digitalWrite(latchPin,LOW); //将ST_CP口上面加低电平让芯片准备好接收数据
          shiftOut(dataPin,clockPin,MSBFIRST,a);
/*这个就是用MSBFIRST参数让0-7个针脚以高电平输出(LSBFIRST 低电平)是dataPin的参数,
clockPin的参数是变量a,前面我们说了这个变量会一次从1+1+到256,是个十进制数,
输入到芯片后会产生8个二进制数,达到开关的作用*/
          digitalWrite(latchPin,HIGH); //将ST_CP这个针脚恢复到高电平
          delay(1000); //暂停1秒钟让你看到效果
        }
}

 
此程序的效果就是通过LED的明灭来表示0或者1,8个二极管就能表示8位二进制数,换算成10进制数的话正好是0-255,与我们程序对应

附录:8位二进制与10进制数字的换算关系

十进制与二进制换算表

十进制:128 64 32 16 8 4 2 1

二进制:0 0 0 0 0 0 0

简单的说,二进制的数值换算十进制按上面的表推算就行了 比如说二进制数101就相当于00000101,按上面表对应得数字就是4和1,4+1=5所以十进制的值就是5,将a这个变量赋值为5的话,led的效果应该是灭灭灭灭灭亮灭亮 ,这个就是所谓的通过三只脚能扩展控制8个脚的原理,因为针脚的作用其实也就是开开关关。。。。

具体换算原理不做深究,请自己查询。

IBM X3650 m3安装windows 2008 x64

本人事先只装过浪潮的服务器,ibm的服务器是第一次见,见天见了真的开眼了,伟大的公司居然连引导盘驱动盘都不送一张,打客服居然下班,伟大的公司下午五点就下班了啊,我这个点才到工地准备干活啊。你让我们这种在内网安装服务器的情何以堪啊。回家再ibm中国官网下载serverguide 居然没有适合x3650 m3的经过一番搜索终于在ibm主站找到了。下载公布一下地址 , 下载完刻盘安装 一路next,这个倒是比浪潮的方便很多。

第 1 页,共 46 页12345...102030...最旧 »