伽利略开发板和BeeMail(三):对象
原型扩展板有利于UNO用于初步检验和伽利略板的转移,从UNO的转移可以确定,伽利略板的I/O引脚在嵌入式启动和Arduino草图启动期间处于上拉状态(取决于5V还是3.3V电压)。
本文引用地址:https://www.eepw.com.cn/article/265933.htm上面所说只是在理想状态下的负逻辑,但马达系统其实并不太适用。这里我按照GPIO的思路将引脚初始化为高电平,看看能不能找出其他办法。
代码部分
以下代码仅为对蜜蜂基于电位计作为输入的测试。若对蜜蜂不加干涉,程序自动上锁,我在这里遇到了麻烦。我去检查串联端口和开发板端口是否正常,可直到现在我仍旧不清楚到底是哪里出了问题。
//------------------------------------------------------------ START LICENSE
/*The MIT License (MIT)
Copyright (c) 2014 Carlyn Maw
特此授权许可,在此情况下本软件免费,并允许任何人复制此软件及相关文档,不限制销售,任何人有权使用、复制、修改、合并、出版、发行、授予执照或销售软件副本,供任何对其有帮助的使用者使用。
以上版权声明和许可声明包括软件所有副本和可观部分。
软件未加任何明指或暗指的担保,按现状出售,但不限于为特定目的和不侵权的适销性及适用性的担保。
在任何情况下,作者或版权持有人,都无权要求任何索赔或有关损害赔偿的其他责任,不管在本软件的使用上或其他买卖交易中是否涉及合同、侵权或其他行为。
*/
// ---------------------------------------------------------------- END LICENSE
//This code is testing code for the circut to make sure all of the
//physical Arduino I/O is working. It checks a potentiometer or other
//sensors on the AO PIN and equates it to the future number of mails
//in the inbox.
//On each pin 9, 10 and 11 are 220 Ohm resistors leading to the bases of
//PN2222A transistors. The collector is attached to the motor and the
//emitter to ground.
//------------------------------------------------- OUTPUTS AND THEIR VARIABLES
//the total number of bees bing controlled
const int beeTotalNumber = 3;
int beePins[beeTotalNumber] = {9, 10, 11 };
//INPUTS AND THEIR VARIABLES
int howManyNewEmails = 0;
//-------------------------------------------------------- GLOBAL BEE SETTINGS
//the number of emails the bees hit maximum freakout.
//ideally it should be divisible by the number of
//beeActivityLevels
int maxBeeVar = 1023;
//how many different states the Bees can be in
const int beeActivityLevels = 16;
//The area that dictates the 16 BeeActivityLevels.
int b[beeActivityLevels][beeTotalNumber] =
{
{ 0, 0, 0 },
{ 0, 0, 50 },
{ 0, 50, 50 },
{ 50, 50, 50 },
{ 50, 50, 100 },
{ 50, 100, 100 },
{ 100, 100, 100 },
{ 100, 100, 150 },
{ 100, 150, 150 },
{ 150, 150, 150 },
{ 150, 150, 200 },
{ 150, 200, 200 },
{ 200, 200, 200 },
{ 200, 200, 250 },
{ 200, 250, 250 },
{ 255, 255, 255 },
};
//---------------------------------------------------------------------- SETUP
void setup() {
Serial.begin(9600);
}
//----------------------------------------------------------------------- LOOP
void loop() {
//get the data determining bee behavior
howManyNewEmails = analogRead(A0);
//Serial.println(howManyNewEmails);
//update the bees
updateBees(howManyNewEmails, maxBeeVar);
//mini-pause
delay(10);
}
//---------------------------------------------------------------- updateBees()
void updateBees(int v, int maxVal) {
//ignore any values of V above maximum freakout level
// v = min(v, maxVal); does not work in Intel Galileo MacOS IDE
if (v > maxVal) {
v = maxVal;
}
//map the newly constrained V to the beeActivityLevel array
//the top value is 1 less than the number than the array size
//because the an array starts with the index number 0
int mappedV = map(v, 0, maxVal, 0, beeActivityLevels-1);
//Serial.println(mappedV);
//for each bee, get the value it supposed to be and set it there
for (int i=0; i <= beeTotalNumber-1; i++){
//Serial.println(b[mappedV][i]);
analogWrite(beePins[i], b[mappedV][i]);
}
}
电容器相关文章:电容器原理
评论